首页 > 代码库 > 28:单词倒排
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; }
28:单词倒排
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。