28:单词倒排

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;
}
原文地址:https://www.cnblogs.com/zwfymqz/p/6485759.html