Advertisement
thouxanbanuno

danila

Jan 18th, 2022
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <math.h>
  5. #include <algorithm>
  6. using namespace std;
  7. string perevod(const string& s){
  8.     vector<int> v;
  9.     int ss = -1;
  10.     for(auto& c: s){
  11.         if(c - '0' > ss){
  12.             ss = c - '0';
  13.         }
  14.         v.push_back(c-'0');
  15.     }
  16.     ss++;
  17.     int ans = 0;
  18.     for(int i = int(v.size()) -1 ; i >= 0; --i){
  19.         ans += v[i] * pow(ss, int(v.size()) - i - 1);
  20.     }
  21.     string str = "";
  22.     while(ans){
  23.         str+=(ans%10 + '0');
  24.         ans/=10;
  25.     }
  26.     reverse(str.begin(), str.end());
  27.     return(str);
  28. }
  29. int main(){
  30.     string s;
  31.     cin>>s;
  32.     string tmp = "";
  33.     string cp = "";
  34.     for(int i = 0 ; i < (int)s.size(); ++i){
  35.         if(isdigit(s[i])){
  36.             tmp+=s[i];
  37.         }
  38.         else{
  39.             if(tmp.size()){
  40.                 auto ans = perevod(tmp);
  41.                 cp+=ans;
  42.             }
  43.             cp+=s[i];
  44.             tmp = "";
  45.         }
  46.     }
  47.     if(tmp.size()){
  48.         auto ans = perevod(tmp);
  49.         cp+=ans;
  50.     }
  51.     cout<<cp;
  52.     return 0;
  53. }
  54. ///aaa010101bbb343ccc => aaa21bbb98ccc
  55. ///qwe136q351e53289e => qwe76q139e53289e
  56. ///315531e136 => 25903e76
  57. ///10 => 2
  58. ///10a => 2a
  59. ///aaa => aaa
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement