1009. Irony (20) time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Chen, Yue
Given an English sentence, you are asked to write a program that reverses the order of all the words in the sentence.
input Format: The test input contains a test case that gives a string with a total length of not more than 80 in a row. The string consists of several words and a number of spaces, where the word is a string of letters (case-sensitive), the words are separated by 1 spaces, and the input guarantees that there are no extra spaces at the end of the sentence.
output format: the output of each test case takes one line, and the output is reversed after the sentence.
Input Sample:
Hello World Here I Come
Sample output:
Come I here World Hello
Idea: Store all words backwards, forward output
1 //1009.cpp: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <string>7#include <vector>8 9 using namespacestd;Ten One intMain () A { - CharC; -vector<string>v; the stringstr; - intJ; - - while(Cin >>str) + { - V.insert (V.begin (), str); + A if((c = GetChar ()) = ='\ n') at Break; - } - -vector<string>::iterator i = V.begin (), end =v.end (); - - for(j = v.size (); j>0; J--, i++) in { -cout << *i; to + if(J! =1) -cout <<" "; the } * $ return 0;Panax Notoginseng}
PAT b 1009 Irony (C + + edition)