StringEqual(https://www.codechef.com/CBST2021/problems/STRG)

Practice

Author: noob_tech
Tester: noob_tech
Editorialist: noob_tech

DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

PREREQUISITES:

String.

PROBLEM:

You are given a string.

If String contains uppercase letter then its same number of lowercase letter must also be present in the string.

If the above condition is satisfied then Print COMPLETED else Print INCOMPLETED.

EXPLANATION:

We are given a string(contains lower as well as upper case letter).We have to check whether the string COMPLETED or INCOMPLETED.
If string Contain UpperCase letter then there same number of the lowercase letter must be present.
It means, consider String contains AAAaaa . Here 3 “A” are present in uppercase letter then its same number Lowercase letter(3 time “a”) is also present in given string .
So output of given string will be COMPLETED.
Consider one more example, String contains AAa. Here 2 ‘A’ is present in uppercase letter but only one ‘a’ is present in lowercase letter.
So this string is incompleted.

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t- -)
{
string s;
cin >> s;
int a[150] = {0};
for (int i = 0; i < s.length(); i++)
{
int k = s[i];
a[k]++;
}
int i;
for (i = 65; i < 91; i++)
{
if (a[i] != a[i + 32])
{
cout << “INCOMPLETED” << endl;
break;
}
}
if (i == 91)
{
cout << “COMPLETED” << endl;
}
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t- -)
{
string s;
cin >> s;
int a[150] = {0};
for (int i = 0; i < s.length(); i++)
{
int k = s[i];
a[k]++;
}
int i;
for (i = 65; i < 91; i++)
{
if (a[i] != a[i + 32])
{
cout << “INCOMPLETED” << endl;
break;
}
}
if (i == 91)
{
cout << “COMPLETED” << endl;
}
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t- -)
{
string s;
cin >> s;
int a[150] = {0};
for (int i = 0; i < s.length(); i++)
{
int k = s[i];
a[k]++;
}
int i;
for (i = 65; i < 91; i++)
{
if (a[i] != a[i + 32])
{
cout << “INCOMPLETED” << endl;
break;
}
}
if (i == 91)
{
cout << “COMPLETED” << endl;
}
}
return 0;
}