4104:单词翻转
来源:互联网 发布:微信淘宝群怎么做到的 编辑:程序博客网 时间:2024/06/07 00:04
4104:单词翻转
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
输入一个句子(一行),将句子中的每一个单词翻转后输出。
- 输入
- 只有一行,为一个字符串,不超过500个字符。单词之间以空格隔开。
- 输出
- 翻转每一个单词后的字符串,单词之间的空格需与原文一致。
- 样例输入
hello world
- 样例输出
olleh dlrow
- 查看
- 提交
- 统计
- 提示
- 提问
#include <stdio.h> //未能AC的代码#include <iostream>#include <stack>#include <string.h>#include <queue>#include <cmath>#include <vector>#include <algorithm>#include <map>#include <set>#include <string>using namespace std;typedef long long LL;#define MAX 1000001bool cmp(pair<string, int> a, pair<string, int> b) { if(a.second != b.second) { return a.second > b.second; } else { return a.first < b.first; }}int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); string str; queue<string> q1; while(cin >> str && str != "\n") { q1.push(str); } int flag = 1; while(!q1.empty()){ string str = q1.front(); q1.pop(); stack<char> s1; for(int i = 0; i < str.size(); i++){ s1.push(str[i]); } while(!s1.empty()){ cout << s1.top(); s1.pop(); } if(q1.size() >= 1){ cout << " " ; } } return 0;}
//AC代码#include <stdio.h>#include <iostream>#include <stack>#include <string.h>#include <queue>#include <cmath>#include <vector>#include <algorithm>#include <map>#include <set>#include <string>using namespace std;typedef long long LL;#define MAX 1000001int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); string str; getline(cin, str); //cout << str << endl; string t =""; for(int i = 0; i < str.size(); i++) { if(str[i] != ' ') { t += str[i]; //cout << t << endl; } else{ //一直有错。。。服气。。没看到题目中的 按照 原来的字符格式进行输出,,就是原来的空格有多少 现在输出的也是多少 PE了一下午。。 if(t != ""){ reverse(t.begin(), t.end()); cout << t; t = ""; } cout << " "; } } //最后的一个单词 是以换行符结尾的 需要单独逆转输出一下 reverse(t.begin(), t.end()); cout << t << endl; return 0;}
阅读全文
0 0
- POJ 4104:单词翻转
- 4104 单词翻转
- 4104:单词翻转
- 百炼 4104:单词翻转
- 单词翻转
- 单词翻转
- 单词翻转
- 翻转单词
- 单词翻转
- 翻转单词
- 单词翻转
- 单词翻转
- 单词翻转
- 单词翻转
- 单词翻转
- 单词翻转
- 单词翻转
- 翻转单词
- 输入输出外挂模板
- IO操作用法简单概述
- 类与类之间的关系
- svn管理idea提交失败代码回退问题
- 数据结构和算法 —— 算法
- 4104:单词翻转
- 2016-2017 HPU暑期集训练习赛
- Leetcode—139. Word Break
- 单调栈(从中间某个位置向左右两侧查找比他大的或者比他小的的边界)
- C语言--ctype.h
- http常见code(40x)
- 用散列表实现学生成绩记录
- 分梨
- HTML学习笔记二