Word Reversal(string)
For each list of words, output a line with each word reversed without changing the order of the words.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
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
1
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
1 #include<stdio.h>
2 #include<iostream>
3 #include<algorithm>
4 #include<string>
5 using namespace std;
6
7 int main()
8 {
9 int t;
10 cin >> t;
11 getchar();
12 while(t--)
13 {
14 int cas;
15 cin >> cas;
16 getchar();
17 while(cas--)
18 {
19 string s, t;
20 getline(cin, s);
21 t.clear();
22 int flag = 0;
23 for(int i = 0; i < s.length(); i++)
24 {
25 if(s[i] != ' ' && i <= s.length() - 1)
26 t += s[i];
27 else
28 {
29 reverse(t.begin(), t.end());
30 if(flag)
31 cout << " ";
32 cout << t;
33 flag = 1;
34 t.clear();
35 }
36 }
37 reverse(t.begin(), t.end());
38 cout << " " << t << endl;
39 }
40 return 0;
41 }
42
43 }
Word Reversal(string)的更多相关文章
- zoj1151 zoj1295 Word Reversal 字符串的简单处理
Word Reversal Time Limit: 2 Seconds Memory Limit:65536 KB For each list of words, output a line ...
- ZOJ 1151 Word Reversal反转单词 (string字符串处理)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151 For each list of words, output a l ...
- Word Reversal
For each list of words, output a line with each word reversed without changing the order of the wo ...
- ZOJ 1151 Word Reversal
原题链接 题目大意:给一句话,把每个单词倒序,然后输出. 解法:我是用了一个堆栈,以空格来拆分单词,把每个字母压入堆栈,然后依次输出. 参考代码: /* * 字符串反向,140ms,188kb * 单 ...
- zoj 1151 Word Reversal(字符串操作模拟)
题目连接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1151 题目描述: For each list of words ...
- Word Reversal (简单字符串处理)
题目描述: For each list of words, output a line with each word reversed without changing the order of th ...
- 139. Word Break (String; DP)
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- 萌新笔记——C++里将string类字符串(utf-8编码)分解成单个字(可中英混输)
最近在建词典,使用Trie字典树,需要把字符串分解成单个字.由于传入的字符串中可能包含中文或者英文,它们的字节数并不相同.一开始天真地认为中文就是两个字节,于是很happy地直接判断当前位置的字符的A ...
- Leetcode: Word Squares && Summary: Another Important Implementation of Trie(Retrieve all the words with a given Prefix)
Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...
随机推荐
- Django的ORM封装接口详细
[前言]Django的orm操作本质上会根据对接的数据库引擎,翻译成对应的sql语句:所有使用Django开发的项目无需关心程序底层使用的是MySQL.Oracle.sqlite....,如果数据库迁 ...
- MHA架构搭建中遇到的问题
1. 两个包:mha4mysql-manager-0.56-0.el6.noarch.rpm 和 mha4mysql-node-0.56-0.el6.norch.rpm 地址:https://code ...
- 《C++ Primer》笔记 第12章 动态内存
shared_ptr和unique_ptr都支持的操作 解释 shared_ptr sp或unique_ptr up 空智能指针,可以指向类型为T的对象 p 将p用作一个条件判断,若p指向一个对象,则 ...
- css标题文字和下划线重叠
<view class="text"> <text class="textCon">标题</text> <text c ...
- rest framework parsers
解析器 机交互的Web服务更倾向于使用结构化的格式比发送数据格式编码的,因为他们发送比简单的形式更复杂的数据 -马尔科姆Tredinnick,Django开发组 REST框架包含许多内置的解析器类,允 ...
- C语言入门-mingw64安装+配置
OK,大家好,结合上期所说,本期让我们来配置编译器吧! 首先先下载mingw64离线包,官网下载慢,可以去群里下载,*.7z格式(有些同学可能没有解压软件,为了照顾这部分同学,笔者提供*.exe格式的 ...
- java 集合 的理解
1.对象的存储:①数组(基本数据类型 & 引用数据类型) ②集合(引用数据类型) >数组存储数据的弊端:长度一旦初始化以后,就不可变:真正给数组元素赋值的个数没有现成的方法可用. 2.集 ...
- 总结数据科学家常用的Python库
概述 这篇文章中,我们挑选了24个用于数据科学的Python库. 这些库有着不同的数据科学功能,例如数据收集,数据清理,数据探索,建模等,接下来我们会分类介绍. 您觉得我们还应该包含哪些Python库 ...
- Maven安装本地依赖包
前提已安装maven并且配置了环境变量1.进入jar包所在的目录,打开cmd2.了解包的groupId.artifactId.version2.输入命令(依赖sdk为例)---maven命令mvn i ...
- Python中类的特殊属性和魔术方法
1.属性 属性 含义 __name__ 类.函数.方法等的名字 __dir__ __module__ 类定义所在的模块名 __class__ 对象或类所属的类 只是返回基类 __bases__ ...