AC日记——单词倒排 1.7 28

28:单词倒排

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

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

输入
输入为一个字符串(字符串长度至多为100)。
输出
输出为按要求排序后的字符串。
样例输入
I am a student
样例输出
student a am I


思路:
  大模拟;


来,上代码:
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

int len,now=0,num=1;

char word[101],word_all[101][50];

int main()
{
    gets(word);
    len=strlen(word);
    for(int i=0;i<len;i++)
    {
        if(word[i]==' ')
        {
            num++;
            now=0;
            continue;
        }
        word_all[num][now++]=word[i];
    }
    printf("%s",word_all[num]);
    for(int i=num-1;i>0;i--)
    {
        printf(" %s",word_all[i]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/IUUUUUUUskyyy/p/6105967.html