(reverse) Text Reverse hdu1062
Text Reverse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 35208 Accepted Submission(s): 13824
Problem Description
Ignatius 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
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 '\n' after the interger T, then you may use gets() to read a line and process it.
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n;
char a[];
cin>>n;
getchar(); //别忘了要输入。
while(n--)
{
gets(a);
int len = strlen(a);
int s=,e=;
for(int i=;i<len;i++)
{
if(a[i]==' ')
{
e = i;
reverse(a+s,a+e); //对于C语言的字符串表示方式使用,但是对于string并不适用。
s=e+;
}
}
if(a[len-]!=' ') //要考虑每行的字符串的最后一个字符是否为空格。
{
e = len;
reverse(a+s,a+e);
}
printf("%s\n",a);
}
return ;
}
(reverse) Text Reverse hdu1062的更多相关文章
- HD-ACM算法专攻系列(7)——Text Reverse
问题描述: 源码: /**/ #include"iostream" #include"string" using namespace std; void Pri ...
- LeetCode(68) Text Justification
题目 Given an array of words and a length L, format the text such that each line has exactly L charact ...
- Javascript高级编程学习笔记(38)—— DOM(4)Text
Text类型 html页面中的纯文本内容就属于Text类型 纯文本内容可以包含转义后的html字符,但不能包括 html 代码 text类型具有以下属性.方法 nodeType:3 nodeName: ...
- React Native组件(三)Text组件解析
相关文章 React Native探索系列 React Native组件系列 前言 此前介绍了最基本的View组件,接下来就是最常用的Text组件,对于Text组件的一些常用属性,这篇文章会给出简单的 ...
- SHELL/VIM删除重复行(去重)text handle
vim 删除重复行 - 国内版 Binghttps://cn.bing.com/search?FORM=U227DF&PC=U227&q=vim+%E5%88%A0%E9%99%A4% ...
- 文件名后面加(1).text
; //在重复名称后加(序号) while (File.Exists(path)) { if (path.Contains(").")) { int start = path.La ...
- (转)EntityFrameword “Reverse Engineer Code First” 连接 MySql
转自:http://stackoverflow.com/questions/19676624/error-trying-to-reverse-engineer-code-first-mysql-dat ...
- LeetCode(150) Evaluate Reverse Polish Notation
题目 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, ...
- leetcode解题报告(27):Reverse Linked List
描述 Reverse a singly linked list. 分析 一开始写的时候总感觉没抓到要点,然后想起上数据结构课的教材上有这道题,翻开书一看完就回忆起来了,感觉解法挺巧妙的,不比讨论区的答 ...
随机推荐
- cordova打包webapp
cordova打包webapp 在项目开发中,需要将h5页面打包成app,这个时候我们可以使用cordova来打包.在官方文档中,我们可以了解到创建一个app十分简单,你的电脑上有nodejs就行,我 ...
- 实践简单的项目WC
#include<iostream> #include<fstream> #include<string> #include<Windows.h> us ...
- 接口(interface)与多态
1. 接口(interface)是抽象方法与常量值的集合: 2. 从本质上来讲,接口是一种特殊的抽象类,这种抽象类中只包含常量与方法的定义,而没有变量和方法的实现: 3. 接口中声明的属性默认为:pu ...
- Atcoder C - Vacation ( DP )
C - Vacation Time Limit: 2 sec / Memory Limit: 1024 MB Score : 100100 points Problem Statement Taro' ...
- 求两个整数的最大公约数GCM
思路分析: (1)求差判定法: 如果两个数相差不大,可以用大数减去小数,所得的差与小数的最大公约数就是原来两个数的最大公约数.例如:求78和60的最大公约数.78-60=18,18和60的最大公约数 ...
- CentOS yum 安装获取原始rpm文件的方法
1. 有时候 yum install 需要从几个repo下载rpm包速度很慢,不如自己能够将rpm包下载下来继续使用,比较好. 发现yum install 有两种方式能够将下载的rpm包保存下来. 方 ...
- pandas切片使用和column赋值
#-*- coding: utf-8 -*- #对数据进行基本的探索 #返回缺失值个数以及最大最小值 import pandas as pd datafile= '../data/air_data.c ...
- pandas 级联 concat append
连接的一个有用的快捷方式是在Series和DataFrame实例的append方法.这些方法实际上早于concat()方法. 它们沿axis=0连接 #encoding:utf8 import pan ...
- WPF将数据库和GridView绑定并更改GridView模板
首先来看一下如何使用GridView,在前台的话代码如下:这里仅仅举出一个例子,GridView是作为子项嵌套在ListView中的,这里的数据源是通过绑定的方式来绑定到GridView中的. < ...
- Log4J日志信息配置文件详解
原文地址: http://blog.csdn.net/wuxintdrh/article/details/78282097 使用log4j 记录日志甚是方便,其提供了两种日志配置方式,log4j.pr ...