For each list of words, output a line with each word reversed without changing   the order of the words.

Input

You will be given a number of test cases. The first line contains a positive   integer indicating the number of cases to follow. Each case is given on a line   containing a list of words separated by one space, and each word contains only   uppercase and lowercase letters.

Output

For each test case, print the output on one line.

Sample Input

3
I am happy today
To be or not to be
I want to win the practice contest

Sample Output

I ma yppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc
#include <iostream>
#include <string>
#include <algorithm>
#include<cstdio>
using namespace std; int main()
{
int cas;
cin >> cas;
getchar();//此处处理回车字符 记住 如果不处理 会出现问题的
while (cas--)
{
string s, t;
getline(cin,s);
t.clear();//每个测试案例之前都要清理掉t 它就是一个类似字符串(就是一个单词)的操作空间
int flag=;
//char str= ' '; 一个空字符不能用字符数组来表示
for ( int i = ; i < s.length() ; i++)
{
//看不太懂你核心代码的意思 有时间可以探讨一下
/* int pos = s.find(str,i);//这儿实现比较复杂
cout<<pos;
int j = s.length() - pos;
int a;
for(; a <= pos && j <= s.length(); a++ , j++)
{
s[a] = t[j];
}
a += pos + 1;*/
//代码思想是:1、不是空格且没到字符串的长度 就把s中的一个一个字母放到t中
// 2、遇到空格 就把它翻转 reverse函数 ;空格 flag来设置,
if(s[i]!=' '&&i<=s.length()-)
t+=s[i];
else
{
reverse(t.begin(),t.end());
if(flag) cout<<" ";
cout<<t;
flag=;//遇到空格 就把flag设置为1 ,等下一个单词t 输出之前 把空格输出来
t.clear();//t 也就是一个单词 故处理下一个单词时 把他清理掉 } }
//这部分你的想法是对的
reverse(t.begin(),t.end());//最后一个单词 它不会出现空格 故放在for循环外面处理
cout<<" "<< t << endl; //输出之前要加空格
} return ;
}

Word Reversal的更多相关文章

  1. zoj1151 zoj1295 Word Reversal 字符串的简单处理

    Word Reversal Time Limit: 2 Seconds      Memory Limit:65536 KB For each list of words, output a line ...

  2. ZOJ 1151 Word Reversal

    原题链接 题目大意:给一句话,把每个单词倒序,然后输出. 解法:我是用了一个堆栈,以空格来拆分单词,把每个字母压入堆栈,然后依次输出. 参考代码: /* * 字符串反向,140ms,188kb * 单 ...

  3. ZOJ 1151 Word Reversal反转单词 (string字符串处理)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151 For each list of words, output a l ...

  4. zoj 1151 Word Reversal(字符串操作模拟)

    题目连接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1151 题目描述: For each list of words ...

  5. Word Reversal (简单字符串处理)

    题目描述: For each list of words, output a line with each word reversed without changing the order of th ...

  6. Word Reversal(string)

    For each list of words, output a line with each word reversed without changing the order of the word ...

  7. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  8. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  9. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

随机推荐

  1. daterangepicker 日期范围插件自定义 可选 年份

    minDate:'01/01/2012',maxDate:'01/01/2015' $("#txtPODate").daterangepicker({ singleDatePick ...

  2. vs2013打开 2010项目时: 请确认 <Import> 声明中的路径正确,且磁盘上存在该文件

    错误原因:原来2010项目中使用的路径是 v11.0,但是我的 C:\Program Files (x86)\MSBuild\12.0\ 是 12.0,所以该成 12.0 解决办法:将项目文件(.cs ...

  3. 利用Columnal网格系统快速搭建网站的基本布局结构

    1.下面是一些对响应式设计提供了不同程度支持的CSS框架: (1)Semantic(http://semantic.gs); (2)Skeleton(http://getskeleton.com); ...

  4. PLSQL Developer的使用

    登陆服务器 除了 sys 用户登陆之外,其他都都选Normal 新建sql 窗口 编写执行sql语句 设置字体.颜色 工具——首选项——用户界面——字体——选择 工具——首选项——用户界面——编辑器— ...

  5. DotNetBar中ListViewEx控件的使用

    最近一直在学习DotNetBar,今天遇到的问题是ListView的使用问题,其实没有特别难的,只是写在这里给自己留个记录. 首先,在Form中添加一个ListViewEx控件, 初始化中写代码如下: ...

  6. markdown 设置字体颜色

    <font color=red>内容</font> markdown.

  7. 【java基础学习】线程

    线程 1. 两种创建方式(继承Thread类和实现Runnable接口) 2. 线程共享资源(建议实现Runnable接口,其好处是:1.多线程之间可以共享资源 2.避免单继承带来的问题 3.数据和代 ...

  8. 带你玩转JavaWeb开发之三 - CSS从基础到实战

    一,什么是CSS? Cascading Style Sheets层叠样式表           层叠:就是层层覆盖叠加,如果有多种样式对同一html标签进行修饰,样式有冲突的部分应用优先级高,不冲突的 ...

  9. 降维技术---PCA

    数据计算和结果展示一直是数据挖掘领域的难点,一般情况下,数据都拥有超过三维,维数越多,处理上就越吃力.所以,采用降维技术对数据进行简化一直是数据挖掘工作者感兴趣的方向. 对数据进行简化的好处:使得数据 ...

  10. jenkins创建job不能用中文问题

    Your Container doesn't use UTF-8 to decode URLs. If you use non-ASCII characters as a job name etc,  ...