Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- bool less_10(char some){
- if (some=='0'||some=='1'||some=='2'||some=='3'||some=='4'||some=='5'||some=='6'||some=='7'||some=='8'||some=='9'){
- return true;
- } else{
- return false;
- }
- }
- int to_num(char a){
- int res;
- if (less_10(a)){
- res = a - 48;
- }else{
- res = a - 'A' + 10;
- }
- return res;
- //cout<< res<<'\n';
- }
- char to_char(ll x){
- char res;
- if (x < 10){
- res = x + 48;
- }else{
- res = x - 10 + 'A';
- }
- return res;
- //cout<<res<<'\n';
- }
- string to_str(int x){
- string res = to_string(x);
- return res;
- }
- ll helper(string num, int from){
- //1 -- перевести в десятичную
- string ans = ""; // в конце перевернём эту строку
- int sz = num.length();
- ll real = 0;
- for(int i = 1; i <= sz; ++i){
- char some = num[i-1]; //digit
- int dig;
- if (less_10(some)){
- dig = some - '0';
- }
- else{
- dig = to_num(some);
- }
- real += dig * pow(from, sz-i);
- }
- return real;
- }
- //2 -- перевести из десятичной в нужную систему
- string convert(ll tenth, int to){
- ll num = tenth;
- string S_num = to_string(num);
- string ans = "";
- while (num > 0){
- char sym; //symbol
- ll dig = num % to;
- sym = to_char(dig);
- ans += sym;
- num /= to;
- }
- //reverse(ans.begin(), ans.end());
- //return ans;
- ans = ans.substr(0, 2);
- reverse(ans.begin(), ans.end());
- return ans;
- }
- string convertX(ll tenth, int to){
- ll num = tenth;
- string S_num = to_string(num);
- string ans = "";
- while (num > 0){
- char sym; //symbol
- int dig = num % to;
- sym = to_char(dig);
- cout<<"dig = "<<dig<<'\n';
- ans += sym;
- num /= to;
- }
- reverse(ans.begin(), ans.end());
- return ans;
- }
- int main()
- {
- /*string num;
- int to, from;
- cin>>from>>num>>to;
- int tenth = helper(num,from);
- string result = convert(tenth, to);
- cout<<result<<'\n';*/
- //1 трактовка: (21 in 16th sys) ^ N
- ll sx21 = helper("21", 16);
- cout<<sx21<<'\n';
- for (ll x = 1; x <= 10;++x){
- cout<<"x = "<<x<<'\n';
- for (ll n = 1;n<=x;++n){
- ll d = pow(sx21, n);
- string s = convert(d, 16);
- //reverse(s.begin(), s.end());
- cout<<"nds= "<<n<<' '<<d<<' '<<s<<'\n';
- //string y = s[1] + s[0];
- ll pl = helper(s, 16);
- }cout<<'\n';
- }
- cout<<"check\n";
- ll q = 1406408618241;
- string r = convertX(q, 16);
- cout<<"r= "<<r<<'\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement