Remove characters from alphanumeric string
PROBLEM :
Remove all characters from an alphanumeric string.
Input:
The first line of the input contains T denoting the number of testcases. First line of each test case will be an alphanumeric string.
Output:
For each test case output will be a numeric string after removing all the characters.
Constraints:
1 <= T <= 30
1 <= size of string <= 100
Example:
Input:
1
AA123BB4
Output:
1234
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<string.h>
int main()
{
int t,i,j,l ;
char str[100] ;
cin>>t ;
while(t--)
{
scanf(" %[^\n]s",str) ;
l=strlen(str) ;
j=0 ;
for(i=0;i<l;i++)
{
if(!((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z')))
{
str[j]=str[i] ;
j++ ;
}
}
str[j]='\0' ;
cout<<str<<endl ;
}
return 0;
}
---------------------------------------------------------------------------------
Remove all characters from an alphanumeric string.
Input:
The first line of the input contains T denoting the number of testcases. First line of each test case will be an alphanumeric string.
Output:
For each test case output will be a numeric string after removing all the characters.
Constraints:
1 <= T <= 30
1 <= size of string <= 100
Example:
Input:
1
AA123BB4
Output:
1234
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<string.h>
int main()
{
int t,i,j,l ;
char str[100] ;
cin>>t ;
while(t--)
{
scanf(" %[^\n]s",str) ;
l=strlen(str) ;
j=0 ;
for(i=0;i<l;i++)
{
if(!((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z')))
{
str[j]=str[i] ;
j++ ;
}
}
str[j]='\0' ;
cout<<str<<endl ;
}
return 0;
}
---------------------------------------------------------------------------------
Comments
Post a Comment