题目简述

给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。



      输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。



输出格式:每个测试用例的输出占一行,输出倒序后的句子。



输入样例

Hello World Here I Come



输出样例

Come I Here World Hello

思路

本题可自己实现split函数,C++使用STL类库较为方便。

C++代码样例

#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std; void split(vector<string>& str, const string& temp_str, const string& flag)
{
string::size_type pos_start, pos_end;
pos_start = 0;
pos_end = temp_str.find(flag);
while(string::npos != pos_end)
{
str.push_back(temp_str.substr(pos_start,pos_end-pos_start));
pos_start = pos_end + flag.size();
pos_end = temp_str.find(flag, pos_start);
}
if(pos_start != temp_str.length())
{
str.push_back(temp_str.substr(pos_start));
}
return;
} int main(void)
{
vector<string> str;
string temp_str = "";
int len = 0;
char input_str[85] = "\0";
gets(input_str);
temp_str = input_str;
split(str,temp_str," ");
for(int i=str.size()-1; i>=0; i--){
printf("%s",(char*)str[i].data());
if(i != 0)
{
printf(" ");
}
}
return 0;
}

最新文章

  1. 微软专家推荐11个Chrome 插件
  2. nyoj 488 素数环
  3. 响应式设计的5个CSS实用技巧
  4. Android中的应用——谷歌官方Json分析工具Gson使用
  5. java打印正金字塔,倒金字塔和“水影”金字塔
  6. Java comparable 和 comparator
  7. Docker常见仓库Node.js
  8. Java8 新特性 | 如何风骚走位防止空指针异常
  9. js里面的判断最好做到完全控制
  10. mysql 删除表 外键出错
  11. TCP的状态转移
  12. 《基于Cortex-M4的ucOS-III的应用》课程设计 结题报告
  13. Jquery实现光棒效果
  14. HtmlRowCreated关于e.Row.Cells[0]的获取和设置
  15. lazy-mock ,一个生成后端模拟数据的懒人工具
  16. 【python3】将视频转换为代码视频
  17. WPF ListBoxItem DataTempldate command 执行问题
  18. 使用nginx反向代理处理前后端跨域访问
  19. 使用defined和require引入js
  20. 关于window.onload和body onload冲突的解决办法

热门文章

  1. 翻译:《实用的Python编程》03_04_Modules
  2. 剑指 Offer 34. 二叉树中和为某一值的路径 + 记录所有路径
  3. 【转载】快速理解android View的测量onMeasure()与MeasureSpec
  4. CSV 注入实战
  5. Webpack 基石 tapable 揭秘
  6. H5 简单实现打砖块游戏
  7. 让你的浏览器变成Siri一样的语音助手
  8. 使用Webpack构建多页面程序
  9. python程序控制结构
  10. 攻防世界 reverse 进阶 notsequence