Reverse-GOOGLE CODE JAM AFICA 2010 Qualification Round

题目来源:http://code.google.com/codejam/contest/dashboard?c=351101#s=p1

拿来练的,这应该是最简单的一道了吧,99%的人都答对了,算法也没什么创新,就是逆序再逆序。。

#include <iostream> #include <fstream> #include <stack> #include <vector> #include <string> using namespace std; int main() { int cnt,i,j; ifstream fcin("B-large-practice.in"); ofstream fcout("B-large-practice.out"); fcin >> cnt; fcin.get(); //回车 vector<string> line; stack<char> str1,str2; string in; char temp; while(cnt>0) { getline(fcin,in); line.push_back(in); cnt--; } i=0; for(vector<string>::iterator it=line.begin();it!=line.end();it++) //对line[i]做处理 { for(j=0;j<(*it).length();j++) { str1.push((*it)[j]); //将所有字符装入str1栈中 } fcout << "Case #" << ++i << ": "; while(!str1.empty()) { temp=str1.top(); str1.pop(); if(temp!=' ') str2.push(temp); if(temp==' '|| str1.empty()) //str2中的字符出栈 { while(!str2.empty()) { fcout << str2.top(); str2.pop(); } fcout << ' '; } } fcout << endl; } return 0; }

 

附录:

Problem

Given a list of space separated words, reverse the order of the words. Each line of text contains L letters and W words. 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

你可能感兴趣的:(list,iterator,character,each,output,2010)