码迷,mamicode.com
首页 > 其他好文 > 详细

28:单词倒排

时间:2017-03-01 19:44:29      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:ios   top   tle   title   长度   stat   str   bsp   page   

28:单词倒排

总时间限制: 
1000ms
 
内存限制: 
65536kB
描述

编写程序,读入一行英文(只包含字母和空格,单词间以单个空格分隔),将所有单词的顺序倒排并输出,依然以单个空格分隔。

输入
输入为一个字符串(字符串长度至多为100)。
输出
输出为按要求排序后的字符串。
样例输入
I am a student
样例输出
student a am I
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a[10001];
char ans[1001][1001];
int now1,now2;
int main()
{
    gets(a);
    int l=strlen(a);
    for(int i=0;i<l;i++)
    {
        if(a[i]!= )
        {
            ans[now1][now2]=a[i];
            now2++;
        }
        else 
        {
            now1++;
            now2=0;
        }
    }
    for(int i=now1;i>=0;i--)
    {
        printf("%s",ans[i]);
        cout<<" ";
    }
    return 0;
}

 

28:单词倒排

标签:ios   top   tle   title   长度   stat   str   bsp   page   

原文地址:http://www.cnblogs.com/zwfymqz/p/6485759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!