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;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )