博客
关于我
B - Text Reverse
阅读量:705 次
发布时间:2019-03-21

本文共 1640 字,大约阅读时间需要 5 分钟。

B - Text Reverse

Ignatius has a peculiar way of writing words. When you receive a line of text from him, your task is to reverse all the words in that line and then output the result. This problem is straightforward but requires careful handling of input and output operations to ensure accuracy.

Input

The input consists of multiple test cases. Each test case is a single line of text containing several words. The line can have up to 1000 characters. The input begins with an integer T indicating the number of test cases. For each test case, you need to process the given line as per the problem requirements.

Output

For each test case, output the text after reversing all the words. Ensure that the output preserves the original structure and formatting of the input line, except for the words being reversed. Remove any leading or trailing spaces that may appear after processing.

Sample Input

3 olleh !dlrow m’I morf .udh I ekil .mca Sample Output hello world! I’m from hdu. I like acm.

Hint

Remember to use `getchar()` to read the newline character after the integer T. Then, use `gets()` to read each line and process it accordingly.
#include 
using namespace std;int main() { int n, i, len; char a[1001]; cin >> n; getchar(); while (n--) { gets(a); len = strlen(a); i = 0; while (i < len && a[i] != ' ') { i++; } for (i--; i >= 0; i--) { if (i == 0) { printf("%c", a[i]); } else if (a[i-1] == ' ') { printf(" "); } printf("%c", a[i]); } printf("\n"); } return 0;}

转载地址:http://xyoez.baihongyu.com/

你可能感兴趣的文章
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>
mysqli
查看>>
MySQLIntegrityConstraintViolationException异常处理
查看>>
mysqlreport分析工具详解
查看>>
MySQLSyntaxErrorException: Unknown error 1146和SQLSyntaxErrorException: Unknown error 1146
查看>>
Mysql_Postgresql中_geometry数据操作_st_astext_GeomFromEWKT函数_在java中转换geometry的16进制数据---PostgreSQL工作笔记007
查看>>
mysql_real_connect 参数注意
查看>>
mysql_secure_installation初始化数据库报Access denied
查看>>
MySQL_西安11月销售昨日未上架的产品_20161212
查看>>
Mysql——深入浅出InnoDB底层原理
查看>>
MySQL“被动”性能优化汇总
查看>>
MySQL、HBase 和 Elasticsearch:特点与区别详解
查看>>
MySQL、Redis高频面试题汇总
查看>>
MYSQL、SQL Server、Oracle数据库排序空值null问题及其解决办法
查看>>
mysql一个字段为空时使用另一个字段排序
查看>>
MySQL一个表A中多个字段关联了表B的ID,如何关联查询?
查看>>