Advertisement
LuckyCipher

Untitled

Oct 29th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include <string>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <stack>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.    
  11.     int amount;
  12.     int same;
  13.     int minLen;
  14.     string tempstr;
  15.     int temp;
  16.     int sum = 0;
  17.    
  18.     cin >> amount;
  19.    
  20.     string arr[amount];
  21.     int priority[amount] = {};
  22.    
  23.     for(int i=0;i<amount;i++)
  24.     {
  25.         cin >> arr[i];
  26.     }
  27.    
  28.     sort(arr,arr+amount);
  29.    
  30.     for(int i=0;i<amount-1;i++)
  31.     {
  32.        
  33.         if(arr[i].at(0) != arr[i+1].at(0))
  34.         {
  35.             continue;
  36.         }
  37.        
  38.         minLen = 0;
  39.         same = 0;
  40.        
  41.         if(arr[i].size()<=arr[i+1].size())
  42.         {
  43.             minLen = arr[i].size();
  44.         }
  45.         else
  46.         {
  47.             minLen = arr[i+1].size();
  48.         }
  49.        
  50.         for(int j=0;j<minLen;j++)  
  51.         {
  52.             if(arr[i].at(j) == arr[i+1].at(j))
  53.             {
  54.                 same++;
  55.             }
  56.             else
  57.             {
  58.                 break;
  59.             }
  60.         }
  61.        
  62.         if(same > priority[i])
  63.         {
  64.             priority[i] = same;
  65.             if(same > priority[i+1])
  66.             {
  67.                 priority[i+1] = same;
  68.             }
  69.         }
  70.        
  71.     }
  72.    
  73.     for(int i=0;i<amount-1;i++)
  74.     {
  75.         for(int j=0;j<amount-1;j++)
  76.         {
  77.             if(priority[j] >= priority[i+1])
  78.             {
  79.                 temp = priority[j];
  80.                 priority[j] = priority[j+1];
  81.                 priority[j+1] = temp;
  82.                
  83.                 tempstr = arr[j];
  84.                 arr[j] = arr[j+1];
  85.                 arr[j+1] = tempstr;
  86.             }
  87.         }
  88.     }
  89.    
  90. //  for(int i=0;i<amount;i++)
  91. //  {
  92. //      cout << arr[i] << endl;
  93. //  }
  94.    
  95.     stack <char> s1;
  96.    
  97.     int notsame = 0;
  98.  
  99.     for(int i=0;i<arr[0].size();i++)
  100.     {
  101.         s1.push(arr[0].at(i));
  102.         cout << arr[0].at(i) << endl;
  103.         sum++;
  104.     }
  105.  
  106.     cout << "output" << endl;
  107.     sum++;
  108.  
  109.     if(amount>1)
  110.     {
  111.         for(int i=0;i<amount-1;i++)
  112.         {
  113.  
  114.             same = 0;
  115.             notsame = 0;
  116.             minLen = 0;
  117.             if(arr[i].size()<=arr[i+1].size())
  118.             {
  119.                 minLen = arr[i].size();
  120.             }
  121.             else
  122.             {
  123.                 minLen = arr[i+1].size();
  124.             }
  125.  
  126.             for(int j=0;j<minLen;j++)
  127.             {
  128.                 if(arr[i].at(j) == arr[i+1].at(j))
  129.                 {
  130.                     same++;
  131.                 }
  132.                 else
  133.                 {
  134.                     break;
  135.                 }
  136.             }
  137.  
  138.             notsame = arr[i].size() - same;
  139.  
  140.             while(notsame>0)
  141.             {
  142.                 if(s1.empty())
  143.                 {
  144.                     break; 
  145.                 }
  146.                 s1.pop();
  147.                 cout << "-" << endl;
  148.                 notsame--;
  149.                 sum++;
  150.             }
  151.  
  152.             for(int k=same;k<arr[i+1].size();k++)
  153.             {
  154.                 s1.push(arr[i+1].at(k));
  155.                 cout << arr[i+1].at(k) << endl;
  156.                 sum++;
  157.             }
  158.             cout << "output" << endl;
  159.             sum++;
  160.  
  161.         }
  162.     }
  163.  
  164.  
  165.     cout << sum <<endl;
  166.  
  167.    
  168.     return 0;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement