senb1

krsu 3333

Mar 10th, 2023
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. /*
  2. by: senb1
  3. */
  4.  
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <string>
  9. #include <numeric>
  10. #include <cmath>
  11. #include <map>
  12.  
  13. #define ll long long
  14. #define yes cout<<"Yes\n"
  15. #define no cout<<"No\n"
  16. #define all(x) x.begin(), x.end()
  17.  
  18. using namespace std;
  19.  
  20. ll bp(ll a, ll n) {
  21.     if (n == 0) return 1;
  22.     if (n % 2) return bp(a, n - 1) * a;
  23.     ll b = bp(a, n / 2);
  24.     return b * b;
  25. }
  26.  
  27.  
  28. void solve() {
  29.     string a, b, s;
  30.     cin >> s;
  31.     a = s.substr(0, s.find('/'));
  32.     b = s.substr(s.find('/') + 1, s.size());
  33.     sort(a.begin(), a.end());
  34.     sort(b.begin(), b.end());
  35.     map <char, int> cnta, cntb;
  36.     for (char c : a) cnta[c]++;
  37.     for (char c : b) cntb[c]++;
  38.     string numerator, denominator;
  39.     for (int c = 'A'; c <= 'Z'; c++) {
  40.         int A = cnta[c];
  41.         int B = cntb[c];
  42.         if (A > B) {
  43.             numerator += char(c);
  44.             if (A - B != 1)
  45.                 numerator += to_string(A - B);
  46.         }
  47.         if (B > A) {
  48.             denominator += char(c);
  49.             if (B - A != 1)
  50.                 denominator += to_string(B - A);
  51.         }
  52.     }
  53.     if (numerator.empty()) {
  54.         cout << 1 << "/";
  55.         if (denominator.empty()) {
  56.             cout << 1;
  57.         }
  58.         else {
  59.             cout << denominator;
  60.         }
  61.     }
  62.     else {
  63.         cout << numerator << "/";
  64.         if (denominator.empty()) {
  65.             cout << 1 << endl;
  66.         }
  67.         else {
  68.             cout << denominator << endl;
  69.         }
  70.     }
  71. }
  72.  
  73. int main() {
  74.     ios::sync_with_stdio(0); cin.tie(0);
  75.     solve();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment