Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // 2017-01-04
- //
- // Created by Jamie on 2017. 5. 20..
- // Copyright © 2017년 Jamie. All rights reserved.
- //
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <sstream>
- #include <vector>
- using namespace std;
- constexpr int ARR_NUM = 5;
- constexpr auto DIVISOR = 1000000007 ; //1,000,000,007;
- string TransNum(string str) {
- auto len = str.length();
- string result(1, str[0]);
- result += "("+ to_string(len) +")";
- return result;
- }
- bool CheckRepeatNum(string str) {
- if( str.length() < 2) return false;
- // 2222
- for( int i=1; i<str.length() ; i++) {
- if( str[i-1] != str[i]) return false;
- }
- return true;
- }
- string CheckResult(vector<int> v) {
- unsigned long sum = 0;
- int index = 0;
- string sum_string;
- // Make Sn
- for( index = 0; ; index++) {
- int readl_index = index % ARR_NUM;
- sum += v[readl_index];
- //cout << "- " << sum << endl;
- sum_string = to_string(sum);
- if ( CheckRepeatNum(sum_string) ) break;
- }
- sum %= DIVISOR;
- string buffer = to_string(index) + " " + TransNum(sum_string);
- return buffer;
- }
- void GetDataFromFile(string filename) {
- ifstream fin(filename);
- string filenameOut = filename.replace(filename.length()-3, 3, ".out");
- ofstream fout(filenameOut);
- if( !fin) {
- cerr << "Cannot open the file" << endl;
- return;
- }
- int totalCase = 0;
- fin >> totalCase; //cout << totalCase << endl
- while ( totalCase--) {
- vector<int> numbers;
- int num=0;
- for(int i=0; i< ARR_NUM ; i++) {
- fin >> num;
- numbers.emplace_back(num);
- }
- cout << CheckResult(numbers) << endl;
- fout << CheckResult(numbers) << endl;
- }
- fout.close();
- fin.close();
- }
- int main(int argc, const char * argv[]) {
- GetDataFromFile("Set1.in");
- // GetDataFromFile("Set2.in");
- // GetDataFromFile("sample_04-sp.in");
- // GetDataFromFile(argv[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement