TechoSagar: Count type of Characters

Search

Google Alert - jobs

Count type of Characters

Given a string S, write a program to count the occurrence of Lowercase characters, Uppercase characters, Special characters and Numeric values in the string.
Input:
First line of input contains a single integer T which denotes the number of test cases. Then T test cases follows. First line of each test case contains a string S.
Output:
For each test case, print four lines. In the first line print the count of upper case letters, in the second line print the count of lower case letters, in the third line print the count of numbers and in the fourth line print the count of special characters present in the string S.

Note: The strings doesnot contains whitespaces.
Constraints:
1<=T<=100
1<=length(S)<=100000
Example:
Input:

2
#GeeKs01fOr@gEEks07
*GeEkS4GeEkS*
Output:
5
8
4
2
6
4
1
2

Get 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;
int x=0,y=0,z=0,w=0;
for(i=0; i<l; i++)
{
if(s[i]>='a'&& s[i]<='z')
{
x++;
}
else if(s[i]>='A'&& s[i]<='Z')
{
y++;
}
 else  if(s[i]>='0'&& s[i]<='9')
{
z++;
}
else
{
w++;
}
}
cout<<y<<endl<<x<<endl<<z<<endl<<w<<endl;
}
}

Follow us

Follow Bijendra Kumar on Facebook