Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- ios::sync_with_stdio(0);
- string a, b, s;
- cin >> s;
- a = s.substr(0, s.find('/'));
- b = s.substr(s.find('/') + 1, s.size());
- // cout << a << " / " << b << endl;
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- map <char, int> cnta, cntb;
- for (char c : a) cnta[c]++;
- for (char c : b) cntb[c]++;
- string numerator, denominator;
- for (int c = 'A'; c <= 'Z'; c++) {
- int A = cnta[c];
- int B = cntb[c];
- if (A > B) {
- numerator += char(c);
- if (A - B != 1)
- numerator += to_string(A - B);
- }
- if (B > A) {
- denominator += char(c);
- if (B - A != 1)
- denominator += to_string(B - A);
- }
- }
- if (numerator.empty()) {
- cout << 1 << "/";
- if (denominator.empty()) {
- cout << 1;
- } else {
- cout << denominator;
- }
- } else {
- cout << numerator << "/";
- if (denominator.empty()) {
- cout << 1 << endl;
- } else {
- cout << denominator << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement