Codeforces 1703A YES or YES? Solution & Explanation

Difficulty : 800

Problem Description

There is a string s of length 3, consisting of uppercase and lowercase English letters. Check if it is equal to “YES” (without quotes), where each letter can be in any case. For example, “yES”, “Yes”, “yes” are all allowable.

Input

The first line of the input contains an integer t(1≤t≤103) — the number of testcases.

The description of each test consists of one line containing one string s consisting of three characters. Each character of s is either an uppercase or lowercase English letter.

Output

For each test case, output “YES” (without quotes) if s satisfies the condition, and “NO” (without quotes) otherwise.

You can output “YES” and “NO” in any case (for example, strings “yES”, “yes” and “Yes” will be recognized as a positive response).

Examples

Input10
YES
yES
yes
Yes
YeS
Noo
orZ
yEz
Yas
XES
OutputYES
YES
YES
YES
YES
NO
NO
NO
NO
NO

Note

The first five test cases contain the strings “YES”, “yES”, “yes”, “Yes”, “YeS”. All of these are equal to “YES”, where each character is either uppercase or lowercase.


Solution

There are two approaches to solve this problem. One approach is to utilize the built-in function string.Compare(), while the other approach involves converting both strings to lowercase (or uppercase) before comparison.

This question is very similar to Codeforces 112A Petya and Strings Solution & Explanation

C# Solution

Solution1string.Compare()

int n = int.Parse(Console.ReadLine());

for(int i=0; i<n; i++){
    var str = Console.ReadLine();
    var res = string.Compare("YES", str , StringComparison.OrdinalIgnoreCase);
    Console.WriteLine(res==0?"YES":"NO");
}

Solution2

int n = int.Parse(Console.ReadLine());

for(int i=0; i<n; i++){
    var str = Console.ReadLine().ToUpper();
    var res = "YES"==str;
    Console.WriteLine(res?"YES":"NO");
}
Klook.com

Conclusion

🧡If my solution helps, that is my honor!

🧡You can support me by sharing my posts, thanks you~~

✅If you got any problem about the explanation or you need other programming language solution, please feel free to let me know !!

The problem link : Problem – 1703A – Codeforces

Random Codeforces Posts

Leave a Reply

Your email address will not be published. Required fields are marked *