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 ...
随机推荐
- visual studio 2013连接Oracle 11g并获取数据:(二:实现)
1.VS中新建一个winform窗体 (1)一个按钮 (2)一个数据表格视图(在里面显示得到的数据表) 2.双击按钮进入代码 (1)添加 using System.Data.OracleClient; ...
- SQL 插入日期时间 变量值
--看看吧^^ CREATE TABLE #temp ( test datetime ) go --SQL: INSERT #temp SELECT 1.1 UNION ALL GO --SQL: I ...
- Android再次激活Activity时触发事件用于列表重新读取载入
@Override protected void onResume(){ super.onResume(); getList(); } 重载 onResume() 方法
- git命令学习用
- python版恶俗古风自动生成器.py
python版恶俗古风自动生成器.py """ python版恶俗古风自动生成器.py 模仿自: http://www.jianshu.com/p/f893291674c ...
- Activity(活动)-再讲
通过多天的学习,大家也了解了adb.exe 是用来进行 客户端(pc)-服务器端(android) 数据交互的. 用户可以使用工具Eclipse 中DDMS 隐示使用 adb.exe 进行连接,也可 ...
- 编译mahout0.9
一.编译的必要性 由于hadoop的生态系统中的各个组建之间的兼容性的问题,因此导致将各个组件组合在一起的时候,会存在一个兼容性的问题,这也是apache hadoop生态系统给开发者带来的一个问题, ...
- Event Handling on Mac
Keyboard/Mouse Event + Cocoa AppleEvent + Cocoa AppleEvent + CommandLine App(w/o UI) + CoreFoundatio ...
- Ant、Maven、Gradle
android Gradle project http://www.ibm.com/developerworks/cn/opensource/os-cn-gradle/ http://www.voge ...
- hdu 2036
Ps: - -感觉这道题完全就是数学题...就是求知道每个顶点的坐标,然后求这个多边形的面积... 代码:#include "stdio.h"#include "std ...