hdoj 练习题1.2.2 字符串反转
2015-11-09 19:59
274 查看
[align=left]Problem Description[/align] Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. |
[align=left]Input[/align] The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a single line with several words. There will be at most 1000 characters in a line. |
[align=left]Output[/align] For each test case, you should output the text which is processed. |
[align=left]Sample Input[/align]3 olleh !dlrow m'I morf .udh I ekil .mca |
[align=left]Sample Output[/align]hello world! I'm from hdu. I like acm.Hint Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it. |
[align=left]Author[/align] Ignatius.L 解题思路: 注意:用getchar()消去录入的换行,用gets()函数直接录入字符串 录入字符串之后设置两个变量uper 和 lower ,以空格为单位反转输出字符串 源代码: # include <stdio.h> # include <string.h> char s[1001]; int main() { int n; while (scanf("%d",&n)!=EOF) { getchar();//接收=0,传过来的空行 while (n--) { gets(s); int lower=0,uper=0; int i=0,j=0; int len=strlen(s); for (i=0;i<len;i++) { while ((s[i]!=' ')&&(s[i]!='\0')) i++; uper=i-1; for (j=uper;j>=lower;j--) printf("%c",s[j]); lower=uper+2; if (s[i]==' ') printf(" "); } printf("\n"); } } return 0; } |
相关文章推荐
- 第121讲:Hadoop集群的格式化、集群运行实战解析等学习笔记
- Win7+Ubuntu双系统启动项修复总结
- 中国剩余定理
- muduo库阅读(9)——线程池
- VS2008LINK : fatal error LNK1000: Internal error during IncrBuildImage编译错误解决办法
- javascript 中关于call方法的详解。
- Codeforces Round #330 (Div. 2) B. Pasha and Phone
- php获取客户端IP
- MapReduce配置
- block中出现此种报错: Incompatible block pointer types initializing 'float (^__strong)(float, float)' with an expression of type 'int (^)(float, float)'
- 第120讲:Hadoop的MapReduce和Yarn的配置实战详解学习笔记
- Beaglebone Black(8)运用Python来进行控制IO,ADC,PWM
- 【创龙TMS320C6748开发板试用】+ 中断学习
- 屏蔽拨号弹出用户和密码的提示框
- 王家林老师的免费大数据视频,欢迎大家下载学习。
- 对Adaboost和SVM的一点直观认识
- Trinea性能优化之性能优化实例
- 处理elasticsearch中的NODENOTAVAILABLEEXCEPTIONS异常
- 不一样的hello world
- View 的 duplicateParentState 属性