daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 53 in 25 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. {
  11.  
  12.     int counter = 0;
  13.  
  14.     ifstream file;
  15.     file.open("input.txt");
  16.    
  17.     string combinations = "";
  18.  
  19.     vector<int> memory(0);
  20.    
  21.     int i;
  22.     while(file>>i)
  23.         memory.push_back(i);
  24.  
  25.     string currentFormation = "";
  26.  
  27.  
  28.     do{
  29.         combinations.append(currentFormation);
  30.         currentFormation = "";
  31.         int maxLocation = 0;
  32.         int max = INT_MIN;
  33.         for(int j=0;j<memory.size();j++)
  34.         {
  35.             if(memory[j] > max)
  36.             {
  37.                 max = memory[j];
  38.                 maxLocation = j;
  39.             }
  40.         }
  41.  
  42.         i = memory[maxLocation];
  43.         memory[maxLocation] = 0;
  44.  
  45.         while(i>0)
  46.         {
  47.             if(maxLocation < memory.size() - 1)
  48.                 maxLocation++;
  49.             else
  50.                 maxLocation = 0;
  51.             memory[maxLocation]++;
  52.             i--;
  53.         }
  54.            
  55.             for(int x=0;x<memory.size();x++)
  56.             {
  57.                 currentFormation.append(to_string(memory[x]));
  58.                 currentFormation.append(",");
  59.             }
  60.             currentFormation.append("  ");
  61.  
  62.             counter++;
  63.     }while(combinations.find(currentFormation) == string::npos);
  64.  
  65.     cout<<"There have been " << counter << " redistribution cycles!"<<endl;
  66.    
  67.     return 0;
  68. }
RAW Paste Data
Top