Contest5.StringReverse
来源:互联网 发布:淘宝精仿鞋店推荐 编辑:程序博客网 时间:2024/06/14 15:04
Description
You will be given a number of test cases. The first line contains the number of cases as a positive integer. Each case is given with a line containing a list of words separated by a space, and each word contains only uppercase and lowercase letters.
Input
The first line contains the number of cases as a positive integer. Each case is given with a line containing a list of words separated by a space, and each word contains only uppercase and lowercase letters.
Output
For each test case, output the result.
Sample Input
3I am goodYou are OKnice char
Sample Output
I ma dooguoY era KOecin rahc
HINT
注意在第一次使用gets()函数时,可能将缓冲区中的\n也接收了,所以在第一个scanf后加一个getchar()
scanf("%d",&n);
getchar();
#include <stdio.h>#include <string.h>void reverseStr(char* str, int i, int j)//将一个字符串中的第i项到第j项反转{ for (; i < j; i++, j--) { char tmp; tmp = str[i]; str[i] = str[j]; str[j] = tmp; } return ;}void reverseWords(char* str)//完成对一句句子的操作{ char* subStrStart;//用Start和End来定义一个单词, char* subStrEnd; //即从第Start项到第End项为一个单词 char* currentPos; //扫描的当前位置 currentPos = &str[0];//扫描位置初始化 while(*currentPos!='\0') { subStrStart = currentPos; while(*currentPos!=' ' && *currentPos!='\0')//得出一个 currentPos++; //单词的长度 subStrEnd = currentPos - 1; reverseStr(str, (int)(subStrStart - &str[0]), (int)(subStrEnd - &str[0])); currentPos++; } return;}void main(){ int n,i; scanf("%d",&n); getchar(); char line[n][250]; for(i=0;i<n;i++) { gets(line[i]); reverseWords(line[i]); printf("%s\n",line[i]); } return ;}
阅读全文
0 0
- Contest5.StringReverse
- 字符串逆转StringReverse
- Hdu 2015 Multi-University Training Contest5
- 2016多校训练Contest5: 1012 World is Exploding hdu5792
- 2016多校训练Contest5: 1007 K-wolf Number hdu5787
- 2016多校训练Contest5: 1005 Interesting hdu5785
- 2016多校训练Contest5: 1003 Divide the Sequence hdu5783
- 2016多校训练Contest5: 1001 ATM Mechine hdu5781
- 2016多校训练Contest5: 1004 How Many Triangles hdu5784
- 2016多校训练Contest5: 1011 Two hdu5791
- 2016多校训练Contest5: 1010 Prefix hdu5790
- 2017多校训练Contest5: 1001 Rikka with Candies hdu6085
- 2017多校训练Contest5: 1006 Rikka with Graph hdu6090
- 2017多校训练Contest5: 1008 Rikka with Subset hdu6092
- Lua: 在C++中将table如何传入到lua中
- 什么是事务,事务的ACID特性
- c++模板队列类
- SpringMvc踩过的坑
- cximage缩略图
- Contest5.StringReverse
- 20171113 自省
- 阿里云ECS CentOS7.2 搭建Shadowscoks
- Linux权限管理之ACL权限最全解读
- 网站知识基础+网站搭建方法
- 对象数组的构造方法
- 在 Python 中实现单例模式
- vue 打包优化
- 2017年做高薪Linux运维最后的机会来了