Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words
2014-04-21 17:28
671 查看
Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words
https://code.google.com/codejam/contest/351101/dashboard#s=p1
Problem
Given a list of space separated words, reverse the order of the words. Each line of text contains
Input
The first line of input gives the number of cases, N.
N test cases follow. For each test case there will a line of letters and space characters indicating a list of space separated words. Spaces will not appear at the start or end of a line.
Output
For each test case, output one line containing "Case #x: " followed by the list of words in reverse order.
Limits
Small dataset
N = 5
1 ≤ L ≤ 25
Large dataset
N = 100
1 ≤ L ≤ 1000
Sample
Solution:
https://code.google.com/codejam/contest/351101/dashboard#s=p1
Problem
Given a list of space separated words, reverse the order of the words. Each line of text contains
Lletters and
Wwords. A line will only consist of letters and space characters. There will be exactly one space character between each pair of consecutive words.
Input
The first line of input gives the number of cases, N.
N test cases follow. For each test case there will a line of letters and space characters indicating a list of space separated words. Spaces will not appear at the start or end of a line.
Output
For each test case, output one line containing "Case #x: " followed by the list of words in reverse order.
Limits
Small dataset
N = 5
1 ≤ L ≤ 25
Large dataset
N = 100
1 ≤ L ≤ 1000
Sample
Input | Output |
3 this is a test foobar all your base | Case #1: test a is this Case #2: foobar Case #3: base your all |
vector<string> solve1(vector<string>words) { reverse(words.begin(), words.end()); return words; } int main() { freopen("in", "r", stdin); //freopen("out", "w", stdout); int t_case_num; scanf("%d\n", &t_case_num); if (!t_case_num) { cerr << "Check input!" << endl; exit(0); } // Read input set for (int case_n = 1; case_n <= t_case_num; case_n++) { string line; getline(cin, line); stringstream ss(line); vector<string>words; string w; while (ss >> w) { words.push_back(w); } auto result = solve1(words); printf("Case #%d: ", case_n); for (int i = 0; i < result.size(); i++) { cout << result.at(i) << " "; } printf("\n"); } fclose(stdin); fclose(stdout); return 0; }
相关文章推荐
- [LeetCode] Path Sum
- Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit
- google hacker技术
- ORA-00119 ORA-00130 bogon
- Go lang concurrency: select with channels
- ubuntu 安装scim+googlepiyin
- BZOJ 1004 [HNOI2008]Cards
- 【Google Glass开发平台】谷歌眼镜开发工具包(GDK)快速...
- Django练习——TodoList
- Django练习——TodoList
- ubuntu12.04 安装sougou拼音
- Google code: Why ‘Everything up-to-date’ when pushing (git)
- 诺基亚 HERE HD Map:Google Maps 的劲敌
- POJ 2195 & hdu 1533 Going Home
- [LeetCode] Convert Sorted Array to Binary Search Tree
- [LeetCode] Merge Two Sorted Lists
- [LeetCode] Merge Sorted Array
- Django中的静态文件管理
- django 配置
- do while(0)的另一个用途:消除goto语句。