TechoSagar: Change the string

Search

Google Alert - jobs

Change the string

Given a string S, the task is to change the string according to the condition; If the first letter in a string is capital letter then change the full string to capital letters, else change the full string to small letters.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. 
Each test case contains a string S.
Output:
For each test case, print the changed string in a new line.
Constraints:
1<=T<=200
1<=|string length|<=104
Example:
Input:
2
geEkS
FoR

Output:
geeks
FOR

Your Code

#include<bits/stdc++.h>

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
int l=s.length();
int i;
if(islower(s[0]))
{
for(i=0; i<l; i++)
{
s[i]=tolower(s[i]);
cout<<s[i];
}
}
else
{
for(i=0; i<l; i++)
{
s[i]=toupper(s[i]);
cout<<s[i];
}
}
cout<<endl;
}

Follow us

Follow Bijendra Kumar on Facebook