EJMAR21F- Editorial

Practice
Contest
Author: Shloka Mahesheka
Tester: SHEKHAR SRIVASTAVA, Akash Kumar Bhagat

DIFFICULTY:

EASY

PROBLEM:

Given N words. Count the number of words in which every letter is present at least once in its uppercase and lowercase.

EXPLANATION:

Create two maps for storing characters in uppercase and lowercase respectively.
Check both the maps simultaneously to see whether the characters are the same or not.
If characters differ that means the character is not present in either one form uppercase or lowercase.
If till the end all characters are the same increase the counter for words.

SOLUTIONS:

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	string s;
	while(t--)
	{
    	int n;
    	cin>>n;
    	int ct=0;
    	while(n--)
    	{
        	cin>>s;
   		int flag=0;
   		map<char,int> capital,small;
   		for(int i=0;i<s.length();++i)
   		{
   	    	if(s[i]>='a' && s[i]<='z')
   	    	small[s[i]]++;
   	    	else 
   	    	capital[s[i]]++;
   		}
   		map<char,int>::iterator itr;
   		Itr=capital.begin();
   		for(auto i:small)
   		{
   	    	if(i.first-32!=itr->first)
   	    	{
   	        	flag=1;
   	        	break;
   	    	}
   	    	++itr;
   		}
   		if(flag==0&& small.size()!=0 && capital.size()!=0)
   		++ct;
   	
	}
	cout<<ct<<"\n";

    	}
   	

	return 0;
}
Tester's Solution
def function1():
	    t = int(input())
	    assert 1<=t<=1000
	    for _ in range(t):
    	    n = int(input())
    	    assert 1<=n<=1000
    	    ans = 0 
    	    for _ in range(n):
        	    w = input().strip()
        	    assert w.isalpha() and 1<=len(w)<=10**5
        	    w = set(w)
        	    # print(w)
        	    f1 = True
        	    for i in range(26):
            	    if (chr(65+i) in w and chr(97+i) not in w) or (chr(97+i) in w and chr(65+i) not in w):
                	    f1 = False 
                	    break 
        	    ans+=f1 
    	    print(and)
    function1()