Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD
DIFFICULTY:
CAKEWALK, SIMPLE, EASY.
PREREQUISITES:
Math .
PROBLEM:
Two strings a and b of equal length are similar, if they have the same character in same position
for example :
“anurag” and “abhish” first position of the letters are same string is similar .
“dog” and “cat” no latter is similar so string is not similar .
EXPLANATION:
We have given two string we have to check all the position with the another string if at same index there is same character then string is similar if we not found any character at similar position then string is not similar
lets take an example
anur abhi if we chech every characters index and its character then we found that there is at first index character is same then string is similar
another example is anur cbhi
in above example at any position there is not similar character at particular position there for string is not similar
SOLUTIONS:
Setter's Solution
#include<bits/stdc++.h>
using namespace std;
void testcase()
{
string s1,s2;
cin>>s1>>s2;
int i=0;
int flag=0;
while(i<s1.size()){
if(s1[i]==s2[i]){
flag=1;
break;
}
i++;
}
if(flag){
cout<<“similar”;
}
else{
cout<<“not similar”;
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}
Tester's Solution
#include<bits/stdc++.h>
using namespace std;
void testcase()
{
string s1,s2;
cin>>s1>>s2;
int i=0;
int flag=0;
while(i<s1.size()){
if(s1[i]==s2[i]){
flag=1;
break;
}
i++;
}
if(flag){
cout<<“similar”;
}
else{
cout<<“not similar”;
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}
Editorialist's Solution
#include<bits/stdc++.h>
using namespace std;
void testcase()
{
string s1,s2;
cin>>s1>>s2;
int i=0;
int flag=0;
while(i<s1.size()){
if(s1[i]==s2[i]){
flag=1;
break;
}
i++;
}
if(flag){
cout<<“similar”;
}
else{
cout<<“not similar”;
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}