Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- string my_to_string(int n){
- string ans;
- while( n > 0 ){
- ans += (n % 10 + '0');
- n /= 10;
- }
- reverse(ans.begin(), ans.end());
- return ans;
- }
- string decode(string code){
- int p = 0;
- string ans, tmp;
- while( p < code.size() ){
- if(code[ p ] >= 'a' and code[ p ] <= 'z'){
- int ile = stoi(tmp);
- while( ile -- ) ans += code[ p ];
- tmp = "";
- }
- else{
- tmp += code[ p ];
- }
- p ++;
- }
- return ans;
- }
- int main()
- {
- string s;
- cin >> s;
- string ans;
- int p = 0;
- while( p < s.size() ){
- int k = p;
- while(s[ p ] == s[ k ]){
- k ++;
- }
- int ile = k - p;
- ans += my_to_string( ile );
- ans += s[ p ];
- p = k;
- }
- cout << ans << endl;
- cout << decode( ans ) << endl;
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement