ZOJ 1151 Word Reversal

来源:互联网 发布:巨灵新闻数据库 编辑:程序博客网 时间:2024/05/18 00:17
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


题意:就是把输入的每个单词反转。

思路:就是一个个读入,一旦碰到空格输出,碰到回车,换行。

代码:

#include <stdio.h>
int main()
{
    char a[100],c;
    int i,j,n,m;
    scanf("%d",&n);
    while(n--){
        scanf("%d\n",&m);
        for(i=0;i<m;i++)
        {
            j=0;
            while((c=getchar())!=EOF)
            {
                if(c==' '||c=='\n')
                {
                    while(j--)printf("%c",a[j]);
                    printf("%c",c);
                    if(c=='\n')
                        break;
                    j=0;
                }
                else
                    a[j++]=c;
            }
        }
        if(n!=0)
            printf("\n");
    }
    return 0;
}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 淘宝已发货买家申请退货怎么办 买家给了一个差评不接电话怎么办 卖家单号填错了怎么办 拼多多虚假发货买家怎么办 买家退款后又收到货怎么办 买家确认收货已超时怎么办 淘宝买家不确认收货怎么办 买家快递单号填错怎么办 买家不确认收货不评价怎么办 淘宝不给改地址怎么办 淘宝快递发货后申请退款怎么办 摄影公司收钱后跑了怎么办 淘宝上申请退款卖家不处理怎么办 淘宝买东西商家发错货退回怎么办 假模特头头发毛燥怎么办 投资了网上融资平台被骗怎么办 微信被覆盖了怎么办 微信号被覆盖了怎么办 样品鞋子在灯光下变黄怎么办 美图秀秀拼图后发朋友圈模糊怎么办 手机重开淘宝网店怎么办 淘宝店铺下架了怎么办 淘宝东西下架了怎么办 淘宝衣服下架了怎么办 淘宝物品下架了怎么办 淘宝货品下架了怎么办 淘宝cmcc下架了怎么办 修手机主板被换怎么办 换手机屏幕被调换零件怎么办 买了东西想退换怎么办 淘宝退货卖家不同意怎么办 淘宝退货退错了怎么办 商品质量问题换货后仍有问题怎么办 货没收到想退款怎么办 淘宝退货店家不退款怎么办 京东退货快递显示签收怎么办 买家已付款卖家不发货怎么办 两个地址发给买家退货怎么办 超市盘点少了货怎么办 月盘点出错领导要理由怎么办 做外汇被坑怎么办?亏损二十多万