ZOJ 1151 Word Reversal反转单词 (string字符串处理)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151
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
本程序包括多组測试数据;
输入数据的第一行是一个整数N,然后是一空行,后面跟着N个数据块,每一个数据块的格式在程序描写叙述中说明了,数据块中有一空行。
输出格式由N个输出块组成,每一个输出块之间有一空行;
输入描写叙述:
现给你多组測试数据,第一行是一个正整数,表示接下来測试数据的组数,每组測试占一行,包括一串单词,中间用一个空格隔开,每一个单词仅包括大小写字母;
输出描写叙述:
每组測试数据都打印在一行上;
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
string s, t;
int n, cas, flag = 0;
char ss[1000];
int main()
{
cin >> cas;
while(cas--) {
scanf("%d", &n);
getchar();
while(n--) {
cin.getline(ss, 1000);
s = ss;
flag = 0;
t.clear();
for(int i=0; i<s.size(); i++) {
if(s[i] != ' ' && i <= s.size()-1) {
t += s[i];
}else {
reverse(t.begin(), t.end());
if(flag) cout << " ";
cout << t;
flag = 1;
t.clear();
}
}
reverse(t.begin(), t.end());
cout << " " << t << endl;
}
if(cas) cout << endl;
}
return 0;
}
ZOJ 1151 Word Reversal反转单词 (string字符串处理)的更多相关文章
- zoj 1151 Word Reversal(字符串操作模拟)
题目连接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1151 题目描述: For each list of words ...
- ZOJ 1151 Word Reversal
原题链接 题目大意:给一句话,把每个单词倒序,然后输出. 解法:我是用了一个堆栈,以空格来拆分单词,把每个字母压入堆栈,然后依次输出. 参考代码: /* * 字符串反向,140ms,188kb * 单 ...
- linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words
1.1 字符操作函数使用 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函 ...
- Word Break II 求把字符串拆分为字典里的单词的全部方案 @LeetCode
这道题相似 Word Break 推断能否把字符串拆分为字典里的单词 @LeetCode 只不过要求计算的并不不过能否拆分,而是要求出全部的拆分方案. 因此用递归. 可是直接递归做会超时,原因是Le ...
- 关于String字符串反转
这是网上看到的一篇java面试题中的问题: 问题是: 如何将一个String字符串反转. String str = "1234567"; int length = str.leng ...
- zoj1151 zoj1295 Word Reversal 字符串的简单处理
Word Reversal Time Limit: 2 Seconds Memory Limit:65536 KB For each list of words, output a line ...
- lintcode:Length of Last Word 最后一个单词的长度
题目: 最后一个单词的长度 给定一个字符串, 包含大小写字母.空格' ',请返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 样例 给定 s = "Hello World& ...
- [LeetCode] Add Bold Tag in String 字符串中增添加粗标签
Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b> and ...
- 北邮OJ103.反转单词 c++/java
103. 反转单词 时间限制 1000 ms 内存限制 65536 KB 题目描述 给出一句英文句子(只由大小写字母和空格组成,不含标点符号,也不会出现连续的空格),请将其中的所有单词顺序翻转 输入格 ...
随机推荐
- ms_sql:drop and create a job
/****** Object: Job [syncData_23_00] Script Date: 09/30/2013 16:48:32 ******/ ) IF EXISTS (SELECT jo ...
- java web 学习十四(JSP原理)
一.什么是JSP? JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. JSP这门技术的最大的特点在于,写jsp就像在写h ...
- XTUOJ 1252 Defense Tower 贪心
题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1252 思路:考虑每条边对玩家的伤害 假设连接的节点是u,v,破坏 ...
- IOS color 颜色值比较
/生成采样对照颜色(黑色) UIColor* sampleColor = [UIColor colorWithRed:(0/255.0f) green:(0/255.0f) blue:(0/255. ...
- duilib relativepos属性导致控件错误的bug修复
转载请说明出处,谢谢~~ 我在仿酷狗音乐播放器的开发日志系列里,曾经提到了这个bug,文章地址为:http://blog.csdn.net/zhuhongshu/article/details/381 ...
- 【Windows核心编程】重载类成员函数new / new[] / delete / delete[]
// Heap.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h> #include &l ...
- Activity的活动周期
Android 使用task来管理Activity.是一个栈的形式.遵循后进先出原则. Activity的四种状态: 运行状态(用户可以操作该Activity).暂停状态(用户可见该Activity, ...
- 对Spring的理解
1.Spring实现了工厂模式的工厂类,这个类名为BeanFactory实际上是一个接口,在程序中通常BeanFactory的子类ApplicationContext.Spring相当于一个大的工厂类 ...
- C语言相关图书推荐
C Primer Plus(第5版 中文版) 作 者 [美] 普拉塔(Prata S.) 著:云巅工作室 编 出 版 社 人民邮电出版社 出版时间 2005-02-01 版 次 1 ...
- Java中的return
比如你写了一个叫getInt的类public int getInt(){ //这个类的意思就是一个具有返回值类型为int的类了 //通常如果不需要返回值的话 这里就写void....//你的具体代码r ...