矫正单词

来源:互联网 发布:鱼鹰软件可信 编辑:程序博客网 时间:2024/04/27 19:23

1.题目:

Problem Description

LJ 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.

Input

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.

Output

For each test case, you should output the text which is processed.

Sample Input

3LJSZnil eij ihs !uhzedam yb .fyb

Sample Output

ZSJLlin jie shi zhu!made by byf.

  Author

byf

 

2.注意事项:

      这题主要要注意一个字符串中有多个空格的情况,还有最后的换行的处理。

 

3.参考代码:

 

 

#include <stdio.h>#include <string.h>int main(){    int t, i, j, l, x, y;    char s[1000];    while (~scanf("%d%*c", &t)) {        while (t--) {            gets(s);            l = strlen(s);            x = 0;            y = 0;            for (i = 0; i < l; i++) {                if (s[i] == ' ') {   ///这种情况是有空格的情况                    y = i;                    for (j = y - 1; s[j] != ' ' && j >= 0; j--)                        printf("%c", s[j]);                    printf(" ");                } else {   ///这是没有空格的情况                    x++;                }            }            if (x == l) {   ///没有空格就逆序输出整个字符串                for (i = l - 1; i >= 0; i--)                    printf("%c", s[i]);            } else {   /// 否则处理最后的'\0'的情况                for (j = l - 1; s[j] != ' '; j--)                    printf("%c", s[j]);            }            printf("\n");        }    }    return 0;}


 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 亲戚赖在家里住怎么办 食堂饭菜味道差该怎么办 被监视居住公安打电话睡着了怎么办 鱼缺氧浮上水面怎么办 车载低音炮有电流声怎么办 925纯银变黑了怎么办 银子放久了变黑怎么办 高铁票网上售空怎么办 高铁票出票失败怎么办 高铁票名字打错怎么办 高铁票姓名错了怎么办 高铁票弄丢了怎么办 用过的车票丢了怎么办 高铁票被水洗了怎么办 沈阳地铁卡丢了怎么办 火车票没写检票口怎么办 吃鸡听的脚步声距离太近怎么办 检票时车票丢了怎么办 高铁出站没检票怎么办 高铁来不及取票怎么办 被发现假的增值税发票怎么办 高铁票身份证验证失败怎么办 网上订的火车票查不到怎么办 已经参加工作想学个本科证怎么办 火车晚点耽误下一趟列车怎么办 门外装监控没有预留电线怎么办 框架柱主筋柱顶预留长度不够怎么办 遇到很嚣张的人怎么办 在地板砖上铺木地板卧室门怎么办 宝宝打预防针的本子丢了怎么办 宝宝打预防针本子丢了怎么办 打疫苗的本子丢了怎么办 麦客收割机麦秸里加麦粒怎么办 高铁乘务员身高不够怎么办 坐火车买到站票怎么办 买上车补票原票怎么办? 买的商务座补票怎么办 12306账号被别人登录怎么办 飞机不提供餐食怎么办 12306退票支付宝失败怎么办 12306重复支付怎么办支付宝