Advertisement
Emiliatan

b586

Jun 2nd, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. /* b586            */
  2. /* AC (2ms, 364KB) */
  3. #include <iostream>
  4. #include <string>
  5. #include <set>
  6. #include <list>
  7.  
  8. using namespace std;
  9.  
  10. const int maxn = 200005;
  11. list<string> lit;
  12. set<string> Set;
  13. string s;
  14.  
  15. string scanString(int &i)
  16. {
  17.     string re;
  18.     while(i < s.length() && !isalpha(s[i])) ++i;
  19.     while(i < s.length() && isalpha(s[i])) re.push_back(s[i++]);
  20.     return re;
  21. }
  22.  
  23. int main()
  24. {
  25.     ios_base::sync_with_stdio(false);
  26.     cin.tie(0), cout.tie(0);
  27.  
  28.     while(getline(cin, s, '\n') && !(s[0] == '0' && s.length() == 1))
  29.     {
  30.         for(int i = 0; i < s.length();)
  31.             if(!isalpha(s[i])) cout << s[i++];
  32.             else
  33.             {
  34.                 string tmp = scanString(i);
  35.                 if(Set.count(tmp))
  36.                 {
  37.                     int cnt = 1;
  38.                     auto it = lit.begin();
  39.                     for(; it != lit.end(); ++it)
  40.                         if(*it != tmp) ++cnt;
  41.                         else break;
  42.                     cout << cnt;
  43.                     lit.erase(it);
  44.                     lit.push_front(tmp);
  45.                 }
  46.                 else
  47.                 {
  48.                     lit.push_front(tmp);
  49.                     Set.insert(tmp);
  50.                     cout << tmp;
  51.                 }
  52.             }
  53.  
  54.         cout << '\n';
  55.     }
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement