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.

对于每个单词列表,输出一个每个单词颠倒的行而不改变单词的顺序。

这个问题包含多个测试用例!

多输入的第一行是整数N,然后是空行,后面是N个输入块。 每个输入块都采用问题描述中指定的格式。 输入块之间有空行。

输出格式由N个输出块组成。 输出块之间有空行。

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

题解:比赛的时候自己想了半天想用栈来模拟这个过程,最后结果是算出来了但是提交的时候Presentation Error(输出格式错误),后来看了别人的blog发现了一些新的操作

1.string中有一个“+”操作就是将两个字符拼接在一起,用在这一道题真的很好

2.getline()函数(具体怎么用还不是太清楚*—*)

此函数会一次读取多个字符(包括空白字符)。它以指定的地址为存放第一个读取的字符的位置,依次向后存放读取的字符,直到读满N-1个,或者遇到指定的结束符为止。若不指定结束符,则默认结束符为'\n'。其语法为:
cin.getline(字符指针(char*),字符个数N(int),结束符(char));
例: #include <iostream>
using namespace std;
int main()
{
char a[30];
cin.getline(a, 10);
for( int i=0; i<10; i++ )
cout << a[i] << " ";
return 0;
}
输入:1234567890123
输出:1 2 3 4 5 6 7 8 9 _ (第10位存放字符串结束符'\0')

  来源:百度百科

我的代码

 1 #include<cstdio>
2 #include<stack>
3 #include<cstring>
4 using namespace std;
5
6 int main()
7 {
8 int t, p;
9 int num;
10 char a[500000];
11 stack<char> s;
12 while(~scanf("%d", &t))
13 {
14 getchar();
15 while(t--)
16 {
17 scanf("%d", &p);
18 getchar();
19 while(p--)
20 {
21 gets(a);
22 int len = strlen(a);
23 for(int i = 0; i < len; i++)
24 {
25 if(a[i] != ' ')
26 s.push(a[i]);
27 else
28 {
29 num = s.size();
30 for(int j = 0; j < num; j++)
31 {
32 printf("%c", s.top());
33 s.pop();
34 }
35 printf(" ");
36 }
37 }
38
39 num = s.size();
40 for(int i = 0; i < num; i++)
41 {
42 printf("%c", s.top());
43 s.pop();
44 }
45 printf("\n");
46 }
47
48 }
49 }
50 return 0;
51 }

AC代码:

 1 #include<iostream>
2 #include<stdio.h>
3 #include<string.h>
4
5 using namespace std;
6
7 int main()
8 {
9 int n;
10 string s;
11
12 scanf("%d", &n);
13 while(n--)
14 {
15 int t;
16 scanf("%d", &t);
17 getchar();
18 while(t--)
19 {
20 getline(cin, s);
21 int l = s.length();
22 string ss = "";
23
24 for(int i = 0; i < l; i++)
25 {
26 if(s[i] != ' ')
27 ss = s[i] + ss;
28 else
29 {
30 cout << ss << " ";
31 ss = "";
32 }
33 }
34 cout << ss << endl;
35 }
36
37 if(n > 0)
38 cout << endl;
39 }
40
41 return 0;
42 }

D - D ZOJ - 1151 (字符串操作)的更多相关文章

  1. ZOJ 3603字符串操作

    解题思路:找到公共子串然后升序输出 坑的地方就在于输入是存在相同字母的 #include <stdio.h> #include <algorithm> #include < ...

  2. python学习笔记(字符串操作、字典操作、三级菜单实例)

    字符串操作 name = "alex" print(name.capitalize()) #首字母大写 name = "my name is alex" pri ...

  3. shell编程常用的截取字符串操作

    1.          常用的字符串操作 1.1.           替换字符串:$ echo ${var/ /_}#支持正怎表达式 / /表示搜索到第一个替换,// /表示搜索到的结果全部替换. ...

  4. php字符串操作集锦

    web操作, 主要就是对字符文本信息进行处理, 所以, 字符串操作几乎占了很大一部分的php操作.包括 注意strstr 和 strtr的区别? 前者表示字符串查找返回字符串,后者表示字符串中字符替换 ...

  5. java 字符串操作和日期操作

    一.字符串操作 创建字符串 String s2 = new String("Hello World"); String s1 = "Hello World"; ...

  6. [No000078]Python3 字符串操作

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- '''Python 字符串操作 string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分 ...

  7. Python 字符串操作及string模块使用

    python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串操作需求: python的字符串属性函数 python的string模块 1.字符串属性方法操作: 1.>字符串格式输出对 ...

  8. C语言字符串操作总结大全

    1)字符串操作 strcpy(p, p1)  复制字符串  函数原型strncpy(p, p1, n)   复制指定长度字符串  函数原型strcat(p, p1)   附加字符串  函数原型strn ...

  9. c# 字符串操作

    一.字符串操作 //字符串转数组 string mystring="this is a string" char[] mychars=mystring.ToCharArray(); ...

随机推荐

  1. LeetCode113. 路径总和 II

    原题链接 1 class Solution: 2 def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]: 3 ans,tm ...

  2. spring boot自定义类配置绑定在配置文件中自动提示

    在spring boot的日常使用中,我们可能需要使用配置绑定的方式动态配置自定义类的成员变量. 这个时候,我们在配置文件中配置spring默认已有的配置时,只需要输入部分关键字即可自动提示,如下图: ...

  3. 剑指 Offer 09. 用两个栈实现队列 +java中栈和队列的使用

    剑指 Offer 09. 用两个栈实现队列 题目链接 class CQueue { private Stack<Integer> sta1; private Stack<Intege ...

  4. #String类简述(小白理解,小白编写,欢迎大神指点,小白跪谢)

    @ 目录 一.前言(可忽略) 二.String变量的认知 三.String类的构造方法 四.String类的基本方法 4.1 toString()方法 4.2 equals()方法 4.3 equal ...

  5. 大数据实战-Spark实战技巧

    1.连接mysql --driver-class-path mysql-connector-java-5.1.21.jar 在数据库中,SET GLOBAL binlog_format=mixed; ...

  6. 200-Java语言基础-Java编程入门-004 | Java分支与循环

    一.流程控制语句 可以控制程序的执行流程 在程序开发的过程之中一共会存在有三种程序逻辑:顺序结构.条件分支(选择)结构.循环结构. 顺序结构的定义,即:所有的程序将按照定义的代码从上往下.顺序依次执行 ...

  7. 前端笔记:React的form表单全部置空或者某个操作框置空的做法

    1.全部置空的做法,一般在弹出框关闭后,需要重置该form所有表单: this.props.form.resetFields(); 2.针对某个操作框置空的做法 例如,form表单里有一个部门和一个张 ...

  8. slickgrid ( nsunleo-slickgrid ) 3 修正区域选择不能跨冻结列的问题

     slickgrid ( nsunleo-slickgrid ) 3 修正区域选择不能跨冻结列的问题 上次解决区域选择不能跨冻结列问题的时候,剩了个尾巴,从右往左选择的时候,会出现选择不正常的情况,后 ...

  9. BIMFACE二次开发【C#系列】

    本系列文章主要介绍使用 C# .ASP.NET(MVC)技术对 BIMFACE 平台进行二次开发,以满足本公司针对建筑行业施工图审查系统的业务需求,例如图纸模型(PDF 文件.二维 CAD 模型.三维 ...

  10. Elasticsearch 复合查询——多字符串多字段查询

    前言 有时我们在搜索电影的时候,包含了多个条件,比如主演是周星驰,打分8分以上,上映时间是1990年~2001年的,那么Elasticsearch又该如何帮我们做查询呢?这里我们可以用 bool 查询 ...