pratiyush7

Untitled

Dec 2nd, 2021
595
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Pratiyush Mishra
  2.  
  3. #include <bits/stdc++.h>
  4. #define ull unsigned long long int
  5. #define ll long long int
  6. #define LL_MAX 9223372036854775807
  7. #define pb push_back
  8. #define pf push_front
  9. #define mp make_pair
  10. #define popb pop_back
  11. #define vl vector<ll>
  12. #define pl pair<ll,ll>
  13. #define bs(v, x) binary_search(v.begin(), v.end(), x)
  14. #define mem1(a) memset(a, -1, sizeof(a))
  15. #define popf pop_front
  16. #define p0(x) cout << x << " "
  17. #define p1(x) cout << x << '\n'
  18. #define p2(x, y) cout << x << " " << y << '\n'
  19. #define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
  20. #define printv(v)                   \
  21.   for (ll i = 0; i < v.size(); ++i) \
  22.     cout << v[i] << " ";            \
  23.   cout << '\n'
  24. #define pr1(x) cout << fixed << setprecision(15) << x << '\n'
  25. #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>
  26. // ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
  27. // s.find_by_order(i)  itertor to ith element (0 indexed)
  28. #define mod 1000000007
  29. #define mod1 998244353
  30. #define fio                         \
  31.   ios_base::sync_with_stdio(false); \
  32.   cin.tie(NULL)
  33. #define get(n) \
  34.   ll n;        \
  35.   cin >> n
  36. #define getvec(v, n)         \
  37.   vector<ll> v(n);           \
  38.   for (ll i = 0; i < n; i++) \
  39.     cin >> v[i];
  40. #define getstr(s) \
  41.   string s;       \
  42.   cin >> s
  43. #define all(x) x.begin(), x.end()
  44. #define countBits(x) __builtin_popcount(x)
  45. using namespace std;
  46.  
  47. int val(char c)
  48. {
  49.   if (c >= '0' && c <= '9')
  50.     return (int)c - '0';
  51.   else
  52.     return (int)c - 'a' + 10;
  53. }
  54. int toDeci(string str, int base)
  55. {
  56.   int len = str.size();
  57.   int power = 1;
  58.  
  59.   int num = 0;
  60.   for (int i = len - 1; i >= 0; i--) {
  61.     if (val(str[i]) >= base) {
  62.       printf("Invalid Number");
  63.       return -1;
  64.     }
  65.     num += val(str[i]) * power;
  66.     power = power * base;
  67.   }
  68.  
  69.   return num;
  70. }
  71.  
  72. char reVal(int num)
  73. {
  74.   if (num >= 0 && num <= 9)
  75.     return (char)(num + '0');
  76.   else
  77.     return (char)(num - 10 + 'a');
  78. }
  79.  
  80. string fromDeci(int base, int inputNum)
  81. {
  82.   string res = "";
  83.   while (inputNum > 0) {
  84.  
  85.     res += reVal(inputNum % base);
  86.     inputNum /= base;
  87.   }
  88.   reverse(res.begin(), res.end());
  89.  
  90.   return res;
  91. }
  92.  
  93. void convertBase(string s, int a, int b)
  94. {
  95.   int num = toDeci(s, a);
  96.   string ans = fromDeci(b, num);
  97.   cout << ans;
  98. }
  99.  
  100.  
  101. void mainSolve()
  102. {
  103.   string x, y;
  104.   int n, m, o;
  105.   cin >> x >> m >> y >> n >> o;
  106.   int ans = toDeci(x, m) * toDeci(y, n);
  107.   string val = to_string(ans);
  108.   convertBase(val, 10, o);
  109. }
  110.  
  111. int main()
  112. {
  113.   fio;
  114. #ifndef ONLINE_JUDGE
  115.   freopen("input.txt", "r", stdin);
  116.   freopen("output.txt", "w", stdout);
  117. #endif
  118.   //get(t);
  119.   ll t = 1;
  120.   while (t--)
  121.   {
  122.     mainSolve();
  123.   }
  124.   return 0;
  125. }
  126.  
RAW Paste Data