Amend The Sentence
PROBLEM :
Problem Description :
You are given an array of characters which is basically a sentence. However there is no space between different words and the first letter of every word is in uppercase. You need to print this sentence after following amendments:
(i) Put a single space between these words
(ii) Convert the uppercase letters to lowercase.
Input:
The first line of input contains the number of test cases. The description of T test case follows.
Each test case contains a single line containing a string.
Output:
Print the desired Sentence.
Constraints:
1<=T<=3
1<=Size of String <=100
Example:
Input :
2
BruceWayneIsBatman
You
Output :
bruce wayne is batman
you
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<malloc.h>
char* Amend_Sentence(char *) ;
int main()
{
int t ;
char *str ;
str=(char*)malloc(100*sizeof(char)) ;
cin>>t ;
while(t--)
{
cin>>str ;
str=Amend_Sentence(str) ;
cout<<str<<endl ;
}
return 0;
}
char* Amend_Sentence(char *str)
{
char *s,*temp ;
s=(char*)malloc(200*sizeof(char)) ;
temp=s ;
if((*str)>='A'&&(*str)<='Z')
{
(*s)=(*str)+32 ;
s++ ;
str++ ;
}
while((*str)!='\0')
{
if((*str)>='A'&&(*str)<='Z')
{
(*s)=' ' ;
s++ ;
(*s)=(*str)+32 ;
s++ ;
}
else
{
(*s)=(*str) ;
s++ ;
}
str++ ;
}
(*s)='\0' ;
return temp ;
}
---------------------------------------------------------------------------------
Problem Description :
You are given an array of characters which is basically a sentence. However there is no space between different words and the first letter of every word is in uppercase. You need to print this sentence after following amendments:
(i) Put a single space between these words
(ii) Convert the uppercase letters to lowercase.
Input:
The first line of input contains the number of test cases. The description of T test case follows.
Each test case contains a single line containing a string.
Output:
Print the desired Sentence.
Constraints:
1<=T<=3
1<=Size of String <=100
Example:
Input :
2
BruceWayneIsBatman
You
Output :
bruce wayne is batman
you
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<malloc.h>
char* Amend_Sentence(char *) ;
int main()
{
int t ;
char *str ;
str=(char*)malloc(100*sizeof(char)) ;
cin>>t ;
while(t--)
{
cin>>str ;
str=Amend_Sentence(str) ;
cout<<str<<endl ;
}
return 0;
}
char* Amend_Sentence(char *str)
{
char *s,*temp ;
s=(char*)malloc(200*sizeof(char)) ;
temp=s ;
if((*str)>='A'&&(*str)<='Z')
{
(*s)=(*str)+32 ;
s++ ;
str++ ;
}
while((*str)!='\0')
{
if((*str)>='A'&&(*str)<='Z')
{
(*s)=' ' ;
s++ ;
(*s)=(*str)+32 ;
s++ ;
}
else
{
(*s)=(*str) ;
s++ ;
}
str++ ;
}
(*s)='\0' ;
return temp ;
}
---------------------------------------------------------------------------------
Comments
Post a Comment