链接: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 <iostream>

#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字符串处理)的更多相关文章

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

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

  2. ZOJ 1151 Word Reversal

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

  3. linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words

    1.1       字符操作函数使用 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函 ...

  4. Word Break II 求把字符串拆分为字典里的单词的全部方案 @LeetCode

    这道题相似  Word Break 推断能否把字符串拆分为字典里的单词 @LeetCode 只不过要求计算的并不不过能否拆分,而是要求出全部的拆分方案. 因此用递归. 可是直接递归做会超时,原因是Le ...

  5. 关于String字符串反转

    这是网上看到的一篇java面试题中的问题: 问题是: 如何将一个String字符串反转. String str = "1234567"; int length = str.leng ...

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

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

  7. lintcode:Length of Last Word 最后一个单词的长度

    题目: 最后一个单词的长度 给定一个字符串, 包含大小写字母.空格' ',请返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 样例 给定 s = "Hello World& ...

  8. [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 ...

  9. 北邮OJ103.反转单词 c++/java

    103. 反转单词 时间限制 1000 ms 内存限制 65536 KB 题目描述 给出一句英文句子(只由大小写字母和空格组成,不含标点符号,也不会出现连续的空格),请将其中的所有单词顺序翻转 输入格 ...

随机推荐

  1. DirectDraw 直接显示RGB图象的最简单实现

      来自:   #include "DDraw.h" class CDDraw { public: void CleanUp(); void DrawDIB(BITMAPINFOH ...

  2. (1)quartz集群调度机制调研及源码分析---转载

    quartz2.2.1集群调度机制调研及源码分析 原文地址:http://demo.netfoucs.com/gklifg/article/details/27090179 引言quartz集群架构调 ...

  3. logback.xml配置

    一:根节点<configuration>包含的属性: scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true. scanPeriod: 设置监测配置文 ...

  4. 对LR analysis的平均事务响应时间和summary中时间值不同的解释

    最近在做性能测试对LR结果分析时,又碰到了关于summary里与平均事务响应时间中各交易的响应时间值不同的问题.在此做个记录. 若交易中设置了思考时间,分析时需要注意查看是否过滤思考时间. 设置是否包 ...

  5. HDU-3001 Travelling

    http://acm.hdu.edu.cn/showproblem.php?pid=3001 从任何一个点出发,去到达所有的点,但每个点只能到达2次,使用的经费最小.三进制 Travelling Ti ...

  6. Selenium IDE 测试

    Selenium IDE 测试 调试是为了发现和修复测试脚本,任何脚本开发的共同步骤是错误的处理.为了使这一过程更加稳固,我们可以使用Selenium IDE的一个插件叫“Power Debugger ...

  7. 提高Web页面性能的技巧

    现在动辄几兆大小的页面加载量,让性能优化成了不可避免的热门话题.WEB 应用越流畅,用户体验就会越好,继而带来更多的访问量.这也就是说,我们应该反省一下那些过度美化的 CSS3 动画和多重操作的 DO ...

  8. pcduino+opencv实现人脸追踪摄像头

    Pcduino是一款兼容Arduino接口的mini pc,A8架构1Ghz的CPU,计算能力不俗,用来跑OpenCV刚刚好.这里就用他们实现一个可以跟随人脸移动的摄像头. 硬件清单: 1.Pcdui ...

  9. bzoj 2002 [Hnoi2010]Bounce 弹飞绵羊(LCT)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2002 [题意] 给定n个数的序列,i可以跳到i+k[i],需要能够修改k并可以查询跳出 ...

  10. MFC使用ShowWindow(SW_MAXIMIZE)任务栏消失的处理

    ShowWindow(SW_SHOWMAXIMIZED);//窗口最大化 问题:在写程序时,如果包含了标题栏,但是没有包含最大化按钮或者最小话按钮. 那么人工用ShowWindow(SW_MAXIMI ...