reverse the given string permanentally.
PROBLEM :
Given a string,reverse it permanentally.
Input:
First line contains an integer, the number of test cases 'T' Each test case should contain an integer, string is inputed in the first line.
Output:
Print the string in reverse order in a single line separated by space.Each string is to be printed in separate line.
Constraints:
1 <= T <= 100
1 <= Arr[i] <= 100
Example:
Input
1
Geeks for Geeks
Output:
skeeG rof skeeG
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<string.h>
int main()
{
char a[100],temp ;
int i,no,t,j ;
cin>>t ;
while(t--)
{
scanf(" %[^\n]s",&a);
no=strlen(a) ;
i=0 ;
j=no-1 ;
while(i<j)
{
temp=a[i] ;
a[i]=a[j] ;
a[j]=temp ;
i++ ;
j-- ;
}
cout<<a<<" " ;
cout<<endl;
}
return 0;
}
---------------------------------------------------------------------------------
Given a string,reverse it permanentally.
Input:
First line contains an integer, the number of test cases 'T' Each test case should contain an integer, string is inputed in the first line.
Output:
Print the string in reverse order in a single line separated by space.Each string is to be printed in separate line.
Constraints:
1 <= T <= 100
1 <= Arr[i] <= 100
Example:
Input
1
Geeks for Geeks
Output:
skeeG rof skeeG
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<string.h>
int main()
{
char a[100],temp ;
int i,no,t,j ;
cin>>t ;
while(t--)
{
scanf(" %[^\n]s",&a);
no=strlen(a) ;
i=0 ;
j=no-1 ;
while(i<j)
{
temp=a[i] ;
a[i]=a[j] ;
a[j]=temp ;
i++ ;
j-- ;
}
cout<<a<<" " ;
cout<<endl;
}
return 0;
}
---------------------------------------------------------------------------------
Comments
Post a Comment