Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* b586 */
- /* AC (2ms, 364KB) */
- #include <iostream>
- #include <string>
- #include <set>
- #include <list>
- using namespace std;
- const int maxn = 200005;
- list<string> lit;
- set<string> Set;
- string s;
- string scanString(int &i)
- {
- string re;
- while(i < s.length() && !isalpha(s[i])) ++i;
- while(i < s.length() && isalpha(s[i])) re.push_back(s[i++]);
- return re;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0), cout.tie(0);
- while(getline(cin, s, '\n') && !(s[0] == '0' && s.length() == 1))
- {
- for(int i = 0; i < s.length();)
- if(!isalpha(s[i])) cout << s[i++];
- else
- {
- string tmp = scanString(i);
- if(Set.count(tmp))
- {
- int cnt = 1;
- auto it = lit.begin();
- for(; it != lit.end(); ++it)
- if(*it != tmp) ++cnt;
- else break;
- cout << cnt;
- lit.erase(it);
- lit.push_front(tmp);
- }
- else
- {
- lit.push_front(tmp);
- Set.insert(tmp);
- cout << tmp;
- }
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement