• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# МИФИ ПИДОРЫ StabCrab  Mar 26th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <algorithm>
3. #include <cmath>
4. using namespace std;
5. int to10(int from, string number)
6. {
7.     int number10 = 0;
8.     int degree = 0;
9.     for (int i = number.length() - 1; i >= 0; i--)
10.     {
11.         if (number[i] <= '9')
12.         {
13.             if (number[i] - 48 >= from || number[i] < 48)
14.             {
15.                 cout << "ERROR";
16.                 return 0;
17.             }
18.             number10 += (number[i] - 48) * pow(from, degree);
19.         }
20.         else
21.         {
22.             if (number[i] - 55 >= from || number[i] > 90)
23.             {
24.                 cout << "ERROR";
25.                 return 0;
26.             }
27.             number10 += (number[i] - 55) * pow(from, degree);
28.         }
29.         degree++;
30.     }
31.
32. }
33. string togiven(int number10, int to)
34. {
35.     string numberto;
36.     while(number10 > 0)
37.     {
38.         if (number10 % to <= '9')
39.             numberto += number10 % to + 48;
40.         else
41.             numberto += number10 % to + 55;
42.         number10 /= to;
43.     }
44.     std :: reverse(numberto.begin(), numberto.end());
45.     return numberto;
46. }
47. int main()
48. {
49.     int from, to;
50.     string number;
51.     cin >> from;
52.     cin >> to;
53.     cin >> number;
54.     if (number == "0" || number == "1")
55.     {
56.         cout << number;
57.         return 0;
58.     }
59.     int number10 = to10(from, number);
60.     string numberto = togiven(number10, to);
61.     cout << numberto;
62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?