博客
关于我
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/

你可能感兴趣的文章
OpenCV与AI深度学习 | 使用Python和OpenCV实现火焰检测(附源码)
查看>>
OpenCV与AI深度学习 | 使用PyTorch进行小样本学习的图像分类
查看>>
OpenCV与AI深度学习 | 使用YOLO11实现区域内目标跟踪
查看>>
OpenCV与AI深度学习 | 使用YOLOv8做目标检测、实例分割和图像分类(包含实例操作代码)
查看>>
OpenCV与AI深度学习 | 使用单相机对已知物体进行3D位置估计
查看>>
OpenCV与AI深度学习 | 十分钟掌握Pytorch搭建神经网络的流程
查看>>
OpenCV与AI深度学习 | 基于GAN的零缺陷样本产品表面缺陷检测
查看>>
OpenCV与AI深度学习 | 基于OpenCV和深度学习预测年龄和性别
查看>>
OpenCV与AI深度学习 | 基于Python和OpenCV将图像转为ASCII艺术效果
查看>>
OpenCV与AI深度学习 | 基于PyTorch实现Faster RCNN目标检测
查看>>
OpenCV与AI深度学习 | 基于PyTorch语义分割实现洪水识别(数据集 + 源码)
查看>>
OpenCV与AI深度学习 | 基于YOLO11的车体部件检测与分割
查看>>
OpenCV与AI深度学习 | 基于YOLOv8 + BotSORT实现球员和足球检测与跟踪 (步骤 + 源码)
查看>>
OpenCV与AI深度学习 | 基于YOLOv8的停车对齐检测
查看>>
OpenCV与AI深度学习 | 基于机器视觉的磁瓦表面缺陷检测方案
查看>>
OpenCV与AI深度学习 | 基于深度学习的轮胎缺陷检测系统
查看>>
OpenCV与AI深度学习 | 实战 | OpenCV传统方法实现密集圆形分割与计数(详细步骤 + 代码)
查看>>
OpenCV与AI深度学习 | 实战 | OpenCV实现扫描文本矫正应用与实现详解(附源码)
查看>>
OpenCV与AI深度学习 | 实战 | 使用YOLOv8 Pose实现瑜伽姿势识别
查看>>
OpenCV与AI深度学习 | 实战 | 使用YoloV8实例分割识别猪的姿态(含数据集)
查看>>