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. Java获取前天和后天的时间

    import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import j ...

  2. 配置非默认端口的监听Listener

  3. 链表的C++实现——创建-插入-删除-输出-清空

    注:学习了数据结构与算法分析后,对链表进行了C++实现,参考博文:http://www.cnblogs.com/tao560532/articles/2199280.html 环境:VS2013 // ...

  4. 在win7下安装unbuntu系统

    1.分盘 准备EasyBCD,ubuntu操作系统 配置EasyBCD,安装ubuntu http://www.linuxidc.com/Linux/2014-04/100369.htm http:/ ...

  5. 拒绝IE8-,CSS3 transform rotate旋转动画效果(支持IE9+/chrome/firefox)

    <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta nam ...

  6. css页面布局基础

    1.盒模型属性包括boder.margin.padding.width.height,这些属性可以使用快捷方式表示,顺序为上右下左,值之间用空格隔开. 2.使用clip和overflow属性时,pos ...

  7. Day12~13(2016/2/1~2/2)

    进度:实现了自定义标题栏控件并调用

  8. SharedPreferences第一次使用后HashMap将常驻内存

    今天使用SharedPreferences的时候突然想到了这个问题,因为我们要存储应用级别的上下文信息,包括用户信息等一系列信息:这个时候使用getSharedPreferences是否合适呢! 其实 ...

  9. iOS 深浅拷贝

    -(void)copyDemo { // 在非集合类对象中:对immutable对象进行copy操作,是指针复制,mutableCopy操作时内容复制:对mutable对象进行copy和mutable ...

  10. DuiLib学习bug整理——某些png不能显示

    今天下午遇到用ps导出的png显示不出来的情况.而从其他来源的png有的可以显示.到群里问了下也有人遇到过,但是都没想明白具体原因.后来经人指点说png保存时存在深度位不同.最后经过测试 8位深度.3 ...