# ML_ALGO22 - Editorial

ML_ALGO22

Setter: aviroop_001
Tester: debrc

Easy

# PREREQUISITES:

String Manipulation

# PROBLEM:

Mr.Hannibal is a Software Engineer, with specialization in Artificial Intelligence. He is really annoyed by the words that have a mix of Upper and Lower case characters.

Thus he wanted to build a software that would change the letters’ register in every word so that it either only consists of lowercase letters or, vice versa, only of uppercase ones.

Mr.Hannibal also wants to make sure that the least number of characters are updated. For example, the word ColOr must be replaced with color; and the word aPPlE — with APPLE. In case a word contains equal number of uppercase and lowercase characters, he should replace all the letters with lowercase ones. For example, bOoK should be replaced by book.

You being the assistant to Mr.Hannibal, help him develop the piece of software.

# EXPLANATION:

Given a string, we only need to count the number of lower and upper case characters. The one with higher number of lower case characters must be fully converted to lower case string ,and vice versa.

# TIME COMPLEXITY

The time complexity is O(N)

# SOLUTIONS:

``````#include<bits/stdc++.h>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
string str;
cin>>str;
int a(0), b(0);
for(auto i: str){
if(i>=97 && i<=122){
a++;    //lower case
}
else b++;   //UPPER CASE
}
if(a<b){
for(int i=0; i<str.length(); i++){
str[i]=toupper(str[i]);
}
}
else{
for(int i=0; i<str.length(); i++){
str[i]=tolower(str[i]);
}
}
cout<<str<<endl;
}
return 0;
}

``````