HUST1339-Reversal

本文介绍了一个简单的字符串反转程序,该程序能够接收一行包含多个单词的文本,并按原顺序输出每个单词的反转形式。文章提供了完整的代码实现及样例输入输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Reversal

时间限制:1秒 内存限制:128兆

258 次提交 138 次通过
题目描述
You will get line with some words(only lowercase and uppercase, no other characters), input it and make all the word reversal and output.
输入
The first line is a number T means there are T cases. For each case: The first line is N means next line has N words. All the words in a line and between two words only one blank. (No more than 100 words, and each word length not exceeded 10)
输出
For each case, output a line with the reversal word in the input order. Between two words has exact one blank, but DO NOT output an blank at the end of a line.
样例输入
3
4
I am a man
4
I will AC it
3
I love ACM
样例输出
I ma a nam
I lliw CA ti
I evol MCA
提示
来源
Zehua Hong


题意:将一句话中的单词倒着输出

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
#include <functional>

using namespace std;

#define LL long long
const int INF=0x3f3f3f3f;

using namespace std;

int main()
{
    int n,m;
    char ch[105][20];
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&m);
            for(int j=0;j<m;j++)
                scanf("%s",ch[j]);
            for(int j=0;j<m-1;j++)
            {
                for(int k=strlen(ch[j])-1;k>=0;k--)
                    printf("%c",ch[j][k]);
                printf(" ");
            }
            for(int k=strlen(ch[m-1])-1;k>=0;k--)
                printf("%c",ch[m-1][k]);
            printf("\n");
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值