1741A - Compare T-Shirt Sizes - CodeForces Solution


implementation implementation strings strings

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    a, b = input().split()
    counter_a = {'L':0,'M':0,'X':0,'S':0}
    counter_b = {'L':0,'M':0,'X':0,'S':0}
    for s in a:
        counter_a[s] += 1
    for d in b:
        counter_b[d] += 1
    if counter_a.get('L') == 1 and counter_b.get('L') ==1:
        if counter_a.get('X') > counter_b.get('X'):
            print('>')
        elif counter_a.get('X') < counter_b.get('X'):
            print('<')
        else:
            print('=')
    elif counter_a.get('L') == 1 and counter_b.get('L') !=1 :
        print('>')
    elif counter_b.get('L') == 1 and counter_a.get('L') != 1 :
        print('<')
    elif counter_a.get('M') == 1 and counter_b.get('M') == 1:
        print('=')
    elif counter_a.get('M') == 1 and counter_b.get('M') != 1:
        print('>')
    elif counter_b.get('M') == 1 and counter_a.get('M') != 1:
        print('<')
    else :
        if counter_a.get('X') < counter_b.get('X'):
            print('>')
        elif counter_a.get('X') > counter_b.get('X'):
            print('<')
        else:
            print('=')

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    int t;
    cin >> t;
    while(t--)
    {
        string a,b;
        cin >> a >> b;
        if(a==b)
        {
            cout << "=\n";
            continue;
        }
        int la = a.size();
        int lb = b.size();
        if(a[la-1]=='S' && b[lb-1] != 'S')
        {cout << "<\n";
         continue;}
        if(a[la-1]=='L' && b[lb-1] != 'L')
        {cout << ">\n";
         continue;}
         if(b[lb-1]=='S' && a[la-1] != 'S')
        {cout << ">\n";
         continue;}
        if(b[lb-1]=='L' && a[la-1] != 'L')
        {cout << "<\n";
         continue;}

         if(a[la-1]=='M')
         {
            if(b[lb-1]=='S')
            cout << ">\n";
            if(b[lb-1]=='L')
            cout << "<\n";
         }
         if(b[lb-1]=='M')
         {
            if(a[la-1]=='S')
            cout << ">\n";
            if(a[la-1]=='L')
            cout << "<\n";
           
         }
         if(a[la-1]==b[lb-1])
         {
            if(a[la-1]=='L')
            {
                if(a.size()>b.size())
                cout << ">\n";
                else
                cout << "<\n";
                continue;
            }
            if(a[la-1]=='S')
            {
                if(a.size()>b.size())
                cout << "<\n";
                else
                cout << ">\n";
                continue;
            }

         }
    }
}


Comments

Submit
0 Comments
More Questions

1607A - Linear Keyboard
EQUALCOIN Equal Coins
XOREQN Xor Equation
MAKEPAL Weird Palindrome Making
HILLSEQ Hill Sequence
MAXBRIDGE Maximise the bridges
WLDRPL Wildcard Replacement
1221. Split a String in Balanced Strings
1002. Find Common Characters
1602A - Two Subsequences
1555A - PizzaForces
1607B - Odd Grasshopper
1084A - The Fair Nut and Elevator
1440B - Sum of Medians
1032A - Kitchen Utensils
1501B - Napoleon Cake
1584B - Coloring Rectangles
1562B - Scenes From a Memory
1521A - Nastia and Nearly Good Numbers
208. Implement Trie
1605B - Reverse Sort
1607C - Minimum Extraction
1604B - XOR Specia-LIS-t
1606B - Update Files
1598B - Groups
1602B - Divine Array
1594B - Special Numbers
1614A - Divan and a Store
2085. Count Common Words With One Occurrence
2089. Find Target Indices After Sorting Array