ZOJ 1151 Word Reversal
- 题目大意:给一句话,把每个单词倒序,然后输出。
- 解法:我是用了一个堆栈,以空格来拆分单词,把每个字母压入堆栈,然后依次输出。
- 参考代码:
/*
* 字符串反向,140ms,188kb
* 单词反向用堆栈是比较方便的,一个个压入,遇到空格再一个个弹出
* 但是不知道为什么耗时这么多,大批的人都是0ms,160kb,难道用字符串处理效率高这么多?
*/ #include<iostream>
#include<string>
#include<stack>
#include<cstdio>
using namespace std; int main(){
int i,j,n,cases;
string str;
char *p,c[80];
stack<char> word; cin>>cases;
while(cases--){
cin>>n;
getline(cin,str);
while(n--){
getline(cin,str);
for(i=0;i<str.size();i++){
if(str[i]!=' '){
word.push(str[i]);
}
else{
while(!word.empty()){
cout<<word.top();
word.pop();
}
cout<<' ';
}
}
while(!word.empty()){
cout<<word.top();
word.pop();
}
cout<<endl;
}
if(cases) cout<<endl;
} return 0;
}
ZOJ 1151 Word Reversal的更多相关文章
- zoj 1151 Word Reversal(字符串操作模拟)
题目连接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1151 题目描述: For each list of words ...
- ZOJ 1151 Word Reversal反转单词 (string字符串处理)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151 For each list of words, output a l ...
- zoj1151 zoj1295 Word Reversal 字符串的简单处理
Word Reversal Time Limit: 2 Seconds Memory Limit:65536 KB For each list of words, output a line ...
- Word Reversal
For each list of words, output a line with each word reversed without changing the order of the wo ...
- Word Reversal (简单字符串处理)
题目描述: For each list of words, output a line with each word reversed without changing the order of th ...
- Word Reversal(string)
For each list of words, output a line with each word reversed without changing the order of the word ...
- D - D ZOJ - 1151 (字符串操作)
For each list of words, output a line with each word reversed without changing the order of the word ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
随机推荐
- POJ 1068 Parencodings 模拟 难度:0
http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...
- C#获取指定日期为一年中的第几周
/// <summary> /// 获取指定日期,在为一年中为第几周 /// </summary> /// <param name="dt">指 ...
- js用正则表达式控制价格输入
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- RM报表 刷新打印机列表
procedure TRMReport.ShowPreparedReport; var s: string; lPreviewForm: TRMPreviewForm; begin RMCurRepo ...
- Hibernate中的一级缓存、二级缓存和懒加载
1.为什么使用缓存 hibernate使用缓存减少对数据库的访问次数,从而提升hibernate的执行效率.hibernate中有两种类型的缓存:一级缓存和二级缓存. 2.一级缓存 Hibenate中 ...
- win10 用微软账户登录无法访问共享的问题
百度找了一大堆可以解决的,最终最简单的方式(可能是bug): 测试了一下,Win10用微软账户登录的,连局域网共享时,输入用户名的时候,前面加个乱七八糟的域名就可以访问了: 比如: 用户名: ba ...
- (转载)Htmlparser Filter 简要归纳
1 . 逻辑关系:与或非 AndFilter() Creates a new instance of an AndFilter. AndFilter(NodeFilter[] pr ...
- Visual Studio 2013 Update 2 and with Update 2
Microsoft 的开发工具 Visual Studio 2013 迎来 Update2 更新.本次更新将为普通开发者带来更多全新功能.修复之前旧版 Bugs.提升性能以及稳定性.之前已经安装 VS ...
- 微软.NET Framework 4.5.2 RTM正式版
今天,微软.NET开发团队发布.NET Framework 4.5.2 RTM正式版.新版框架继续高度兼容现有的.NET Framework 4.4.5.4.5.1等版本,该版本框架与旧版的.NET ...
- 2013年7月底至8月初51Aspx源码发布详情
兼职人员信息管理系统源码 2013-8-2 [VS2008]2013.8.2更新内容:修改了一级菜单不能修改的bug.功能介绍:兼职人员信息管理:添加,修改,删除,查询,支持数据导出Excel,按多 ...