原题链接

    题目大意:给一句话,把每个单词倒序,然后输出。
    解法:我是用了一个堆栈,以空格来拆分单词,把每个字母压入堆栈,然后依次输出。
    参考代码:
/*
* 字符串反向,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的更多相关文章

  1. zoj 1151 Word Reversal(字符串操作模拟)

    题目连接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1151 题目描述: For each list of words ...

  2. ZOJ 1151 Word Reversal反转单词 (string字符串处理)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151 For each list of words, output a l ...

  3. zoj1151 zoj1295 Word Reversal 字符串的简单处理

    Word Reversal Time Limit: 2 Seconds      Memory Limit:65536 KB For each list of words, output a line ...

  4. Word Reversal

    For each list of words, output a line with each word reversed without changing   the order of the wo ...

  5. Word Reversal (简单字符串处理)

    题目描述: For each list of words, output a line with each word reversed without changing the order of th ...

  6. Word Reversal(string)

    For each list of words, output a line with each word reversed without changing the order of the word ...

  7. D - D ZOJ - 1151 (字符串操作)

    For each list of words, output a line with each word reversed without changing the order of the word ...

  8. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  9. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

随机推荐

  1. 12个强大的Chrome插件

    Chrome功能强大,也得益于其拥有丰富的扩展资源库.Chrome Web Store里有各种各样的插件,可以满足你使用Chrome时的各种要求.和Firefox一样,Chrome的扩展非常容易安装, ...

  2. IE9的css hack

    以前写过<IE8的css hack>,ie9一出css hack也该更新,以前一直没关注,今天在内部参考群mxclion分享了IE9的css hack,拿出来也分享一下: select { ...

  3. C++中的容器类详解

    一.STL容器类 STL(Standard Template Library)的六大组件:容器(containers).迭代器(iterators).空间配置器(allocator).配接器(adap ...

  4. dialog参数、方法以及事件

    参数(options) DOM方式初始化dialog的,推荐使用集合属性data-options定义参数,如果使用data属性定义参数,注意转换成对应的名称. 名称 类型 默认值 描述 id stri ...

  5. 学习js之类的使用

    <script language="javascript">function Person(){    }Person.prototype={    name:null ...

  6. 块状元素和内联元素 【inline block】

    // 9) { colorRandom += colorArray[randomV - 10]; } else { colorRandom += randomV; } } currentEle.css ...

  7. poj2955 区间dp

    //Accepted 200 KB 63 ms //区间dp //dp[i][j] 从i位到j位能得到的最大匹配数 //dp[i][j]=max(dp[i+1][j-1] (s[i-1]==s[j-1 ...

  8. PAT 06-2 字符串字母大小写转换

    没什么好说的,记得使用ctype.h就好了,谭浩强那本书就介绍了,再不使用就太对不起他老人家了:有一点小小的地方需要注意一下,&&的优先级比=号高,所以getchar()两边没有括号的 ...

  9. 利用pl/sql developer进行远程连接oracle server出现的问题及解决办法

    由于本人刚刚给自己的笔记本做了系统,由原来的32位系统编程现在的64位系统,所以,很多软件由于兼容性,不得不重新安装...当我安完了pl/sql developer工具后,就满心欢喜的去连接远程ora ...

  10. hive 中 union all

    hive 中的union all是不能在sql语句的第一层使用的,否则会报 Top level UNION is not supported currently 错误: 例如如下的方式: select ...