原题链接

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

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. HDU 1394 Minimum Inversion Number

    //============================================================================ // Name : B.cpp // Au ...

  3. html圆角提示效果

    <fieldset> <legend>标题</legend> 内容 </fieldset>

  4. java web 之 web.xml篇

    web.xml文件 标签: 1. <web-app> 顶层标签,所有web.xml必须包含该标签.在该标签中,描述了当前Servlet版本以及其他一些信息. 2. <servlet& ...

  5. JAVA每日一旅3

    1.关于byte byte在内存中占一个字节,范围是-128-127,128作强制类型转换到byte变成-128,因为128的二进制表示:1000 0000,最高位是符号位. 2.关于Hibernat ...

  6. linux内核编译

    1,进入内核源码树,如果是第一次编译,建议清理以下内核功能选择文件: make mrproper 2,删除前一次编译的残留文件: make clean 3,配置内核功能 make menuconfig ...

  7. iphone判断当前网络连接类型

    eachability只能区分出无网络.wifi和wwan(2G&2.5G&3G)类型的网络连接类型,只需重构networkStatusForFlags方法,即可详细区分出2G与3G网 ...

  8. Oracle Data Integrator与OWB的集成及迁移

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  9. Cocoa Drawing

    Graphics Contexts Graphics contexts are a fundamental part of the drawing infrastructure in Cocoa ap ...

  10. Design Patterns---- Strategy 模式

    设计模式:可复用面向对象软件的基础 书中对 Strategy 模式的定义如下: 定义了一系列的算法,把它们一个个封装起来,并且使它们可相互替换.本模式使得算法可独立于它的用户而变化. 案例:设计一个商 ...