Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <algorithm>
- #include <iostream>
- #include <stack>
- using namespace std;
- int main()
- {
- int amount;
- int same;
- int minLen;
- string tempstr;
- int temp;
- int sum = 0;
- cin >> amount;
- string arr[amount];
- int priority[amount] = {};
- for(int i=0;i<amount;i++)
- {
- cin >> arr[i];
- }
- sort(arr,arr+amount);
- for(int i=0;i<amount-1;i++)
- {
- if(arr[i].at(0) != arr[i+1].at(0))
- {
- continue;
- }
- minLen = 0;
- same = 0;
- if(arr[i].size()<=arr[i+1].size())
- {
- minLen = arr[i].size();
- }
- else
- {
- minLen = arr[i+1].size();
- }
- for(int j=0;j<minLen;j++)
- {
- if(arr[i].at(j) == arr[i+1].at(j))
- {
- same++;
- }
- else
- {
- break;
- }
- }
- if(same > priority[i])
- {
- priority[i] = same;
- if(same > priority[i+1])
- {
- priority[i+1] = same;
- }
- }
- }
- for(int i=0;i<amount-1;i++)
- {
- for(int j=0;j<amount-1;j++)
- {
- if(priority[j] >= priority[i+1])
- {
- temp = priority[j];
- priority[j] = priority[j+1];
- priority[j+1] = temp;
- tempstr = arr[j];
- arr[j] = arr[j+1];
- arr[j+1] = tempstr;
- }
- }
- }
- // for(int i=0;i<amount;i++)
- // {
- // cout << arr[i] << endl;
- // }
- stack <char> s1;
- int notsame = 0;
- for(int i=0;i<arr[0].size();i++)
- {
- s1.push(arr[0].at(i));
- cout << arr[0].at(i) << endl;
- sum++;
- }
- cout << "output" << endl;
- sum++;
- if(amount>1)
- {
- for(int i=0;i<amount-1;i++)
- {
- same = 0;
- notsame = 0;
- minLen = 0;
- if(arr[i].size()<=arr[i+1].size())
- {
- minLen = arr[i].size();
- }
- else
- {
- minLen = arr[i+1].size();
- }
- for(int j=0;j<minLen;j++)
- {
- if(arr[i].at(j) == arr[i+1].at(j))
- {
- same++;
- }
- else
- {
- break;
- }
- }
- notsame = arr[i].size() - same;
- while(notsame>0)
- {
- if(s1.empty())
- {
- break;
- }
- s1.pop();
- cout << "-" << endl;
- notsame--;
- sum++;
- }
- for(int k=same;k<arr[i+1].size();k++)
- {
- s1.push(arr[i+1].at(k));
- cout << arr[i+1].at(k) << endl;
- sum++;
- }
- cout << "output" << endl;
- sum++;
- }
- }
- cout << sum <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement