Advertisement
Darkdonkie

Untitled

May 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  2017-01-04
  4. //
  5. //  Created by Jamie on 2017. 5. 20..
  6. //  Copyright © 2017년 Jamie. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <string>
  11. #include <fstream>
  12. #include <sstream>
  13. #include <vector>
  14.  
  15. using namespace std;
  16.  
  17. constexpr int   ARR_NUM = 5;
  18. constexpr auto  DIVISOR = 1000000007 ; //1,000,000,007;
  19.  
  20. string TransNum(string str) {
  21.     auto len = str.length();
  22.     string result(1, str[0]);
  23.    
  24.     result += "("+ to_string(len) +")";
  25.     return result;
  26. }
  27.  
  28. bool CheckRepeatNum(string str) {
  29.    
  30.     if( str.length() < 2) return false;
  31.     // 2222
  32.     for( int i=1; i<str.length() ; i++) {
  33.         if( str[i-1] != str[i]) return false;
  34.     }
  35.     return true;
  36. }
  37.  
  38. string CheckResult(vector<int> v) {
  39.    
  40.     unsigned long sum = 0;
  41.     int index = 0;
  42.     string sum_string;
  43.  
  44.     // Make Sn
  45.     for( index = 0; ; index++) {
  46.         int readl_index = index % ARR_NUM;
  47.         sum += v[readl_index];
  48.         //cout << "- " << sum << endl;
  49.        
  50.         sum_string = to_string(sum);
  51.        
  52.         if ( CheckRepeatNum(sum_string) ) break;
  53.     }
  54.     sum %= DIVISOR;
  55.    
  56.     string buffer = to_string(index) + " " + TransNum(sum_string);
  57.     return buffer;
  58. }
  59.  
  60. void GetDataFromFile(string filename) {
  61.     ifstream fin(filename);
  62.     string filenameOut = filename.replace(filename.length()-3, 3, ".out");
  63.     ofstream fout(filenameOut);
  64.    
  65.     if( !fin) {
  66.         cerr << "Cannot open the file" << endl;
  67.         return;
  68.     }
  69.    
  70.     int totalCase = 0;
  71.     fin >> totalCase; //cout << totalCase << endl
  72.    
  73.     while ( totalCase--) {
  74.         vector<int> numbers;
  75.         int num=0;
  76.        
  77.         for(int i=0; i< ARR_NUM ; i++) {
  78.             fin >> num;
  79.             numbers.emplace_back(num);
  80.         }
  81.         cout << CheckResult(numbers) << endl;
  82.         fout << CheckResult(numbers) << endl;
  83.     }
  84.    
  85.     fout.close();
  86.     fin.close();
  87. }
  88.  
  89. int main(int argc, const char * argv[]) {
  90.    
  91.     GetDataFromFile("Set1.in");
  92. //    GetDataFromFile("Set2.in");
  93. //    GetDataFromFile("sample_04-sp.in");
  94.    
  95. //    GetDataFromFile(argv[1]);
  96.    
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement