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 ...
随机推荐
- Flask:Jinjia模板
Jinja2是Python下一个被广泛应用的模版引擎,他的设计思想来源于Django的模板引擎,并扩展了其语法和一系列强大的功能. 一.变量 1.1 手动传入的变量: 基本类型:{{ var }} 字 ...
- 【Java进阶面试系列之一】哥们,你们的系统架构中为什么要引入消息中间件?
转: [Java进阶面试系列之一]哥们,你们的系统架构中为什么要引入消息中间件? **这篇文章开始,我们把消息中间件这块高频的面试题给大家说一下,也会涵盖一些MQ中间件常见的技术问题. 这里大家可以关 ...
- PAT-1147(Heaps)最大堆和最小堆的判断+构建树
Heaps PAT-1147 #include<iostream> #include<cstring> #include<string> #include<a ...
- node.js详解1
1.运行node脚本 新建app.js 写入代码console.log('hello') cmd终端执行 node app.js 2.node读取环境变量 浏览器地址:ht ...
- 普通的一天,说一个普通的XML
什么是XML XML全称是Extensible Markup Language,译为"可扩展标记语言",常用来存储和传输信息. XML的结构 我们经常看到的XML文件是这个样子的: ...
- Git代码分支开发工作流程
本文的工作流程,有一个共同点:都采用"功能驱动式开发"(Feature-driven development,简称FDD). 它指的是,需求是开发的起点,先有需求再有功能分支(fe ...
- NewSQL分布式数据库,例如TIDB用K/V的底层逻辑
内容参考 对分布式对定义参考这篇文章: 微服务都想用,先把分布式和微服务之间的关系说清楚 对分布式架构中心或无中心对比参考这篇文章: 分布式存储单主.多主和无中心架构的特征与趋势 对HDFS对内部机制 ...
- Qt update刷新之源码分析(三)
大家好,我是IT文艺男,来自一线大厂的一线程序员 上次视频给大家从源码层面剖析了Qt刷新事件(QEvent::UpdateRequest)的处理流程,这次视频主要从源码层面剖析对刷新事件的进一步处理, ...
- Java 树结构实际应用 二(哈夫曼树和哈夫曼编码)
赫夫曼树 1 基本介绍 1) 给定 n 个权值作为 n 个叶子结点,构造一棵二叉树,若该树的带权路径长度(wpl)达到最小,称这样的二叉树为 最优二叉树,也称为哈夫曼树(Huffman Tree), ...
- Codeforces Round #558 B2. Cat Party (Hard Edition)
题面: 传送门 题目描述: 题意:确定最大的x,使去除掉前x天的其中一天后,所有不同数字的数量相等. 题目分析: 可能是我太久没打cf了,水题都做不出来. 这道题的关键在于:要记录相同数量,的不同 ...