Skip to content

Instantly share code, notes, and snippets.

@peaceman
Created April 15, 2011 12:52
Show Gist options
  • Save peaceman/921644 to your computer and use it in GitHub Desktop.
Save peaceman/921644 to your computer and use it in GitHub Desktop.
/*
* File: main.cpp
* Author: NaegeleNi
*
* Created on 15. April 2011, 13:57
*/
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
typedef std::vector<std::string> tStringVector;
/*
*
*/
int main(int argc, char** argv) {
std::ifstream inputFile("h:/input.txt", std::fstream::in);
std::ofstream outputFile("h:/output.txt", std::fstream::out);
if (inputFile.fail() || outputFile.fail()) {
std::cout << "Konnte eine der beiden Dateien nicht oeffnen" << std::endl;
}
int nrOfTestCases;
inputFile >> nrOfTestCases;
std::string line;
for (int i = 0; i < nrOfTestCases; i++) {
std::getline(inputFile, line);
std::stringstream lineStream(line);
tStringVector words;
std::string word;
while (std::getline(lineStream, word, ' ')) {
words.push_back(word);
}
outputFile << "Case #" << i + 1 << ":";
for (tStringVector::reverse_iterator iter = words.rbegin(); iter < words.rend(); iter++) {
outputFile << " " << *iter;
}
outputFile << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment