HDU——1062Text Reverse(水题string::find系列+reverse)
Text Reverse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24157 Accepted Submission(s): 9311
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
olleh !dlrow
m'I morf .udh
I ekil .mca
I'm from hdu.
I like acm.
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
刚开始发现最后一个单词和前一个连在一块了,改了一个地方就过了,本打算用stringstream重定向,想想好麻烦der,还是用最喜欢的string系列函数吧.还好string支持加号运算
代码:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main(void)
{
int t,loc;
cin>>t;
getchar();
string s1;
while (t--)
{
getline(cin,s1);
loc=0;
while (s1.find(" ",loc)!=string::npos)//反转前n-1个单词
{
reverse( s1.begin()+loc , s1.begin()+s1.find(" ",loc) );
loc=s1.find(" ",loc)+1;//更新每次反转的begin位置
}
reverse( s1.begin()+s1.find_last_of(" ")+1 , s1.end() );//反转最后一个单词
cout<<s1<<endl;
}
return 0;
}
HDU——1062Text Reverse(水题string::find系列+reverse)的更多相关文章
- hdu 5210 delete 水题
Delete Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...
- hdu 1251 (Trie水题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU——1020Encoding(水题,string过)
Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 4493 Tutor 水题的收获。。
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...
- hdu 4802 GPA 水题
GPA Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
- hdu 5003 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=5003 记得排序后输出 #include <cstdio> #include <cstring& ...
- HDU 4696 Answers 水题
http://acm.hdu.edu.cn/showproblem.php?pid=4696 由题意可知 1<=Ci<=2 而且图上一定有环 那么我们可以得出: 只要存在奇环(即Ci=1) ...
随机推荐
- 四、filter和find函数的区别
filter(): filter函数会返回data中为true那项的数组(即查询符合条件的数据) eg:data.filter((f)=>{ if(f[name]===item[name]){ ...
- Harvest of Apples
问题 B: Harvest of Apples 时间限制: 1 Sec 内存限制: 128 MB提交: 18 解决: 11[提交] [状态] [讨论版] [命题人:admin] 题目描述 Ther ...
- J.U.C知识点梳理
java.util.concurrent : 提供了并发编程的解决方案 1.CAS 是java.util.concurrent.atomic包的基础 2.AQS是java.util.concurren ...
- ajax的序列化表单提交
通过传统的 form 表单提交的方式上传文件 ? 1 2 3 4 <form id="uploadForm" action="" method=" ...
- 性能优化之MySQL优化(慕课)
MySQL数据库优化 1-1MySQL优化简介 数据库优化的目的 避免出现页面访问错误 由于数据库连接timeout产生5XX错误 由于慢查询造成页面无法加载 由于阻塞造成数据无法提交 增加数据库的稳 ...
- 【转】MFC 程序入口和执行流程
一 MFC程序执行过程剖析 1)我们知道在WIN32API程序当中,程序的入口为WinMain函数,在这个函数当中我们完成注册窗口类,创建窗口,进入消息循环,最后由操作系统根据发送到程序窗口的消息调用 ...
- 【dsu || 线段树合并】bzoj4756: [Usaco2017 Jan]Promotion Counting
调半天原来是dsu写不熟 Description The cows have once again tried to form a startup company, failing to rememb ...
- 使用linux安装gitolite管理git
系统:centos7 服务器:阿里云 一.前期准备 1.安装git yum install git 2.安装perl yum install perl 3.安装openssh yum install ...
- spdlog&rapidjson 使用记录
项目中需要记录log以及读写json,对比后选择了spdlog以及rapidjson. SPDLog 对于log只是要求能够记录到文件中以及能够过滤,选择spdlog是因为这个只需要包含头文件即可使用 ...
- 【linux】 服务器文件说明
文件名 说明 /etc/resolv.conf 域名解析服务器地址文件 /etc/services 服务程序对应端口号文件 /etc/passwd 登录账号文件 /etc/hosts 本地IP域名解 ...