zoj1151 zoj1295 Word Reversal 字符串的简单处理
Word Reversal
Time Limit: 2 Seconds Memory Limit:65536 KB
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
http://blog.csdn.net/AC_0_summer/article/details/44747401
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
char s[];
void _S()
{
int L=;
s[L++]=getchar();
while(s[L-]!='\n'){
if(s[L-]==' ')
{
for(int i=L-;i>=;i--)
putchar(s[i]);
printf(" ");
L=;
}
s[L++]=getchar();
}
for(int i=L-;i>=;i--)
putchar(s[i]);
printf("\n");
return ;
} int main()
{
int n,T; scanf("%d",&T);
while(T--){
scanf("%d\n",&n);//过滤换行符
while(n--) _S();
if(T) printf("\n"); //此题容易因为此处PE
}
return ;
}
zoj1295:
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
void _S()
{
char s[];
int num=;
char c=getchar();
while(true){
if(c=='\n'){
for(int i=num;i>=;i--) cout<<s[i];
cout<<endl;
return ;
}
s[++num]=c;
c=getchar();
}
}
int main()
{
int n;
scanf("%d\n",&n);
while(n--)
_S()
return ;
}
为什么感觉题目没有解释很清楚,让那么多人PE。。。。。。。。。。。
当然本题处理方式有很多,也可以每一行输入后再处理。个人属于习惯单个字符输入的那种(此时要注意过滤换行符什么的)。
zoj1151 zoj1295 Word Reversal 字符串的简单处理的更多相关文章
- zoj 1151 Word Reversal(字符串操作模拟)
题目连接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1151 题目描述: For each list of words ...
- 【Android进阶】Gson解析json字符串的简单应用
在客户端与服务器之间进行数据传输,一般采用两种数据格式,一种是xml,一种是json.这两种数据交换形式各有千秋,比如使用json数据格式,数据量会比较小,传输速度快,放便解析,而采用xml数据格式, ...
- java生成RSA公私钥字符串,简单易懂
java生成RSA公私钥字符串,简单易懂 解决方法: 1.下载bcprov-jdk16-140.jar包,参考:http://www.yayihouse.com/yayishuwu/chapter ...
- MiniWord .NET Word模板引擎,藉由Word模板和数据简单、快速生成文件。
Github / Gitee QQ群(1群) : 813100564 / QQ群(2群) : 579033769 介绍 MiniWord .NET Word模板引擎,藉由Word模板和数据简单.快速生 ...
- Word Reversal (简单字符串处理)
题目描述: For each list of words, output a line with each word reversed without changing the order of th ...
- ZOJ 1151 Word Reversal反转单词 (string字符串处理)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151 For each list of words, output a l ...
- 对上次“对字符串进行简单的字符数字统计 探索java中的List功能 ”程序,面向对象的改进
之前的随笔中的程序在思考后发现,运用了太多的static 函数,没有将面向对象的思想融入,于是做出了一下修改: import java.util.ArrayList; import java.util ...
- 对字符串进行简单的字符数字统计 探索java中的List功能
题目: 统计一个字符串中数字和字符串的个数,并分别进行排列,要求 1.数字,字符串可以从键盘获取. 2.储存在list 3.统计数字个数,字符串个数 4.把数字和字符串按从小到大的顺序输出 5.不能使 ...
- Word Reversal
For each list of words, output a line with each word reversed without changing the order of the wo ...
随机推荐
- 【C++小白成长撸】--N阶幻方(魔阵)矩阵
解决方法:1.第一个元素放在第一行中间一列 2.下一个元素存放在当前元素的上一行.下一列. 3.如果上一行.下一列已经有内容,则下一个元素的存放位置为当前列的下一行. 在找上一行.下一行或者下一列的时 ...
- GUI(JTabel表格)
/** * */ package com.niit.javagui; import java.util.Vector; import javax.swing.ImageIcon; import jav ...
- 201521123025《java程序设计》第8周学习总结
1. 本周学习总结 2.书面作业 Q1.List中指定元素的删除(题目4-1) public static List<String> convertStringToList(String ...
- 201521123017 《Java程序设计》第5周学习总结
1. 本周学习总结 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分析输出结果. 1.2 ...
- 201521123122《Java程序设计》第1周学习总结
1. 本周学习总结 因为寒假里也没有好好预习java,第一周上课还是有点懵逼. ①.了解了JVM,JRE,JDK的区别,能够熟练安装JDK. ②.编了我人生中的第一个java程序"hello ...
- Java第十一周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) ...
- 启用Oracle中的scott用户
启用Oracle中的scott用户 在Linux系统上安装Oracle服务器,有的不含有scott用户,有的scott用户被锁.下面是添加scott用户或解锁scott. 一. 验证scott用户是否 ...
- 嵌入系统squashfs挂载常见问题总结
由于squahsfs的一些优点,嵌入系统常常直接使用squashfs作为initrd挂载到/dev/ram,作为rootfs.这里对常见的一些问题进行一些分析. 1. kernel启动出现错误 RAM ...
- 【BBED】BBED模拟并修复ORA-08102错误
[BBED]BBED模拟并修复ORA-08102错误 1.1 BLOG文档结构图 1.2 前言部分 1.2.1 导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其 ...
- JVM菜鸟进阶高手之路五
转载请注明原创出处,谢谢! 参考gc,发现大概一小时运行一次FGC,特别奇怪,笨神一看这样的问题就知道是system gc导致的,rmi默认一小时主动触发一次,由于没有gc日志,通过jstat命令观察 ...