fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7.  
  8. int main() {
  9.  
  10. long long x = 0;
  11. int y;
  12. int i = 0;
  13. string s;
  14.  
  15.  
  16.  
  17. cin >> s >> y;
  18.  
  19.  
  20.  
  21.  
  22.  
  23. for (auto it = s.begin(); it != s.end(); it++)
  24. {
  25. char c = *it;
  26. if (c >= 'A' && c <= 'Z')
  27. x += pow(y, i) * (c - 'A' + 10);
  28. else
  29. x += pow(y, i) * (c - '0');
  30. i++;
  31. }
  32.  
  33. cout << x;
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 15232KB
stdin
10 2
stdout
1