Text Reverse hdu1062 水题

来源:互联网 发布:炉石代练软件 编辑:程序博客网 时间:2024/05/29 19:36

http://acm.hdu.edu.cn/showproblem.php?pid=1062

需要注意的就是,单词与单词之间的空格都是要输出的。。有几个空格就输出几个空格。还有这个题的空白只有空格,没有/t等其它的符号。

莫名的就感觉这个题目好坑人。 一开始提交的几次都表达错了,想了很久也没想明白。。 =w=

#include <iostream>#include <string.h>using namespace std;#define N 1005char s[N],t[N];void print(char *str){  //反向输出。int i;for (i=strlen(str)-1;i>=0;i--)printf("%c",str[i]);}int main(){#ifndef ONLINE_JUDGEfreopen("1062in.txt","r",stdin);#endifint c,len,i,j;scanf("%d",&c);getchar();while (c--){gets(s);len=strlen(s);s[len]=' ';s[len+1]='\0';t[0]='\0';for (i=0,j=0;i<=len;i++){if (s[i]==' '){ //如果遇到空格就输出t,t用来记录非空格的字符。print(t);t[0]='\0';printf("%c",i==len?'\n':' ');j=0;continue;}else {t[j]=s[i];j++;t[j]='\0'; //用斜杠0记录终点,这个很重要哦。=w=}}}return 0;}


原创粉丝点击