原题链接

    题目大意:给一句话,把每个单词倒序,然后输出。
    解法:我是用了一个堆栈,以空格来拆分单词,把每个字母压入堆栈,然后依次输出。
    参考代码:
/*
* 字符串反向,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. 汉字转拼音Pinyin4j工具(C#、Java都可用)

    C#用法: string pinyin=GetStringPinYin("张三"); //方法如下 public static string GetStringPinYin(str ...

  2. Mac OS X 卸载MySQL

    sudo rm /usr/local/mysqlsudo rm -rf /usr/local/mysql*sudo rm -rf /Library/StartupItems/MySQLCOMsudo ...

  3. centos=>gsutil,iptables

    sudo apt-get remove --purge gsutil sudo easy_install -U pip  sudo pip2 install gsutil gsutil ls gs:/ ...

  4. ASP.NET 学习笔记

    1.ASP.NET 服务器控件是可被服务器理解的标签 有三种类型的服务器控件(所有服务器控件必须出现在 <form> 标签内,同时 <form> 标签必须包含 runat=&q ...

  5. HDU 3333 树状数组离线查询

    题目大意: 询问区间内不同种类的数的数值之和 这里逐个添加最后在线查询,会因为相同的数在区间内导致冲突 我们总是希望之后添加的数不会影响前面,那么我们就在添加到第i个数的时候,把所有在1~i 的区间的 ...

  6. English test for certificate

    <英语口译全真试题精解> GPA 3.5 (MTI)  (CPA) ( GRE )  1350分+3.5以上 SAT ( TOEFL )  100分以上 TOEIC BEC (剑桥商务英语 ...

  7. IOS开发中--点击imageView上的Button没有任何反应

    点击imageView上的Button没有任何反应:    解决方法:设置图片的userInteractionEnabled为YES,使该imageView可以与用户进行交互

  8. python建立pip.ini

    pip 是python的包管理器工具,类似linux的apt-get.yum包管理器,主要是用来进行安装python库, pip默认从官方源pypi.python.org下载数据,国内速度相对比较慢, ...

  9. MySQL数据类型(四)

    一.数据类型 二.整型类型 tinyInt: 1个字节:-128-127(有符号) 是否有符号,可以定义时,使用unsign标识,表示无符号的,不写表示有符号的 Create table studen ...

  10. WIN中SharePoint Server 2010 入门安装部署详解

    目前流行的原始安装文件基本都是这样的:Windows Server 2008 R2+SQL Server 2008R2+SharePoint Server 2010     这个初始环境原本也无可厚非 ...