 # GOS2021- Editorial

Author: Setter’s name
Tester: Tester’s name

EASY

Strings.

# PROBLEM:

You will be given three strings S1, S2 and a universal string S. You have to find out whether string S1 or string S2 has more common letters with universal string S. If string S1 has more common letters with string S then print “WIN” else you have to print out “LOSE”.

# QUICK EXPLANATION:

You can simply traverse string S1 and S and find the count of common letters in a variable then you can traverse string S2 and S and find count of common letters in another variable. Finally you can compare both the variables and print “WIN” or “LOSE” as output depending on whichever is the bigger.

# EXPLANATION:

This question can be simply solved by using two simple pointers that we use to traverse two different strings. We use nested for loops and compare each element of universal string S with each element of string S1. While comparing these elements, if we find out that both the elements are equal then we just increment the counter. After the end of both for loops we will be getting a value for our counter which will represent the number of common letters between string S1 and S. Let’s say that we store this value in counter1.

Similarly we use nested for loops to compare string S2 and S. At the end of these loops we will get a counter value that will represent the number of common letters between string S2 and S. Suppose we store this value in another variable counter2.

Now for the last step we just have to compare both the variables, counter1 and counter2, and print the output.

If:

• counter1 > counter2 print “WIN” (without quotation marks).
• counter1 < counter2 print “LOSE” (without quotation marks).

# ALTERNATE EXPLANATION:

You can further simplify the code by using set i.e. only using unique characters from universal string rather than using the original string with duplicate values.

# SOLUTIONS:

Setter's Solution
``````#include<bits/stdc++.h>
#include<string>
using namespace std;

string check(string s1,string s2,string s)
{
int ct1=0,ct2=0;
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<s.length();j++)
{
if(s1[i]==s[j])
ct1++;
}
}
for(int i=0;i<s2.length();i++)
{
for(int j=0;j<s.length();j++)
{
if(s2[i]==s[j])
ct2++;
}
}
return ct1>ct2?"WIN":"LOSE";
}
int main()
{
string s1,s2,s;
cin>>s1>>s2>>s;
cout<<check(s1,s2,s);
return 0;

}
``````
Tester's Solution
``````def main():
s1= input()
s2= input()
s= input()
count1= 0
count2= 0
for i in s:
if i in s1:
count1+=1
if i in s2:
count2+=1
if count1>count2:
print("WIN")
else:
print("LOSE")

if _name_ =="_main_":
main()
``````