Advertisement
Korotkodul

ИТМО. N1

Nov 27th, 2021 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <vector>
  5. #include <string>
  6. #include <cstdio>
  7. #include <algorithm>
  8. using namespace std;
  9. using ll = long long;
  10.  
  11. bool less_10(char some){
  12. if (some=='0'||some=='1'||some=='2'||some=='3'||some=='4'||some=='5'||some=='6'||some=='7'||some=='8'||some=='9'){
  13. return true;
  14. } else{
  15. return false;
  16. }
  17. }
  18.  
  19. int to_num(char a){
  20. int res;
  21. if (less_10(a)){
  22. res = a - 48;
  23. }else{
  24. res = a - 'A' + 10;
  25. }
  26. return res;
  27. //cout<< res<<'\n';
  28. }
  29.  
  30. char to_char(ll x){
  31. char res;
  32. if (x < 10){
  33. res = x + 48;
  34. }else{
  35. res = x - 10 + 'A';
  36. }
  37. return res;
  38. //cout<<res<<'\n';
  39. }
  40.  
  41.  
  42. string to_str(int x){
  43. string res = to_string(x);
  44. return res;
  45. }
  46.  
  47.  
  48.  
  49. ll helper(string num, int from){
  50. //1 -- перевести в десятичную
  51. string ans = ""; // в конце перевернём эту строку
  52. int sz = num.length();
  53. ll real = 0;
  54. for(int i = 1; i <= sz; ++i){
  55. char some = num[i-1]; //digit
  56. int dig;
  57. if (less_10(some)){
  58. dig = some - '0';
  59. }
  60. else{
  61. dig = to_num(some);
  62. }
  63. real += dig * pow(from, sz-i);
  64. }
  65. return real;
  66. }
  67. //2 -- перевести из десятичной в нужную систему
  68. string convert(ll tenth, int to){
  69. ll num = tenth;
  70. string S_num = to_string(num);
  71. string ans = "";
  72. while (num > 0){
  73. char sym; //symbol
  74. ll dig = num % to;
  75. sym = to_char(dig);
  76. ans += sym;
  77. num /= to;
  78. }
  79. //reverse(ans.begin(), ans.end());
  80. //return ans;
  81. ans = ans.substr(0, 2);
  82. reverse(ans.begin(), ans.end());
  83. return ans;
  84. }
  85.  
  86. string convertX(ll tenth, int to){
  87. ll num = tenth;
  88. string S_num = to_string(num);
  89. string ans = "";
  90. while (num > 0){
  91. char sym; //symbol
  92. int dig = num % to;
  93. sym = to_char(dig);
  94. cout<<"dig = "<<dig<<'\n';
  95. ans += sym;
  96. num /= to;
  97. }
  98. reverse(ans.begin(), ans.end());
  99. return ans;
  100. }
  101.  
  102. int main()
  103. {
  104. /*string num;
  105. int to, from;
  106. cin>>from>>num>>to;
  107. int tenth = helper(num,from);
  108. string result = convert(tenth, to);
  109. cout<<result<<'\n';*/
  110. //1 трактовка: (21 in 16th sys) ^ N
  111. ll sx21 = helper("21", 16);
  112. cout<<sx21<<'\n';
  113. for (ll x = 1; x <= 10;++x){
  114. cout<<"x = "<<x<<'\n';
  115. for (ll n = 1;n<=x;++n){
  116. ll d = pow(sx21, n);
  117. string s = convert(d, 16);
  118. //reverse(s.begin(), s.end());
  119. cout<<"nds= "<<n<<' '<<d<<' '<<s<<'\n';
  120. //string y = s[1] + s[0];
  121. ll pl = helper(s, 16);
  122. }cout<<'\n';
  123. }
  124. cout<<"check\n";
  125. ll q = 1406408618241;
  126. string r = convertX(q, 16);
  127. cout<<"r= "<<r<<'\n';
  128. }
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement