Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Solution for:
- // https://code.google.com/codejam/contest/3264486/dashboard
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <sstream>
- const std::string INPUT_FILE_PATH = "D:\\Downloads\\input.txt";
- const std::string OUTPUT_FILE_PATH = "D:\\Downloads\\output.txt";
- int main()
- {
- unsigned short LineNumber = -1;
- std::ofstream OutputFile;
- std::ifstream InputFile;
- OutputFile.open( OUTPUT_FILE_PATH.c_str(), std::ios::trunc );
- InputFile.open ( INPUT_FILE_PATH.c_str() );
- std::string line;
- while( std::getline(InputFile, line) )
- {
- if( ++LineNumber == 0 ) continue; // increase the line number but skip the first one (due to it being the number of lines)
- std::cout << "Now doing line: " << LineNumber+1 << std::endl;
- std::string Pancakes = "";
- int SizeFlipper = 0;
- // Generate Pancakes & SizeFlipper variables
- std::string tmp_sizeflipper = "";
- for(unsigned int i=0; i<line.length(); ++i)
- {
- if(line[i]=='-' || line[i]=='+')
- Pancakes.push_back(line[i]);
- if(line[i]>='0' && line[i]<='9')
- tmp_sizeflipper.push_back(line[i]);
- }
- SizeFlipper = atoi( tmp_sizeflipper.c_str() );
- // Start flipping!
- int Flips = 0;
- for(unsigned int i=0; i<Pancakes.length()-SizeFlipper+1; ++i)
- {
- if( Pancakes[i]=='-' )
- {
- for(unsigned int t=0; t<SizeFlipper; ++t)
- {
- Pancakes[i+t] = (Pancakes[i+t]=='-'?'+':'-');
- }
- Flips++;
- }
- }
- // Okay then let's generate the results!
- std::stringstream stream;
- stream << Flips;
- std::string Flips_Result = stream.str();
- for(unsigned int i=0; i<Pancakes.length(); ++i)
- {
- if(Pancakes[i]=='-')
- {
- Flips_Result = "IMPOSSIBLE";
- break;
- }
- }
- OutputFile << "Case #" << LineNumber << ": " << Flips_Result << std::endl;
- }
- OutputFile.close();
- InputFile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment