Code For Alls..!

get the code!!

Monday 18 September 2017

Three Strings

                                                                          Three Strings
Three Strings


Given N string values, the program must print 3 string values as the output as described in the Example Input/Output section.
Input format:
The first line will contain N denoting the number of string values.
Next N lines will contain the N string values.
Output format:
Three lines containing string values as described in the Example Input/Output section.
Example Input/Output 1:
Input:
3
JOHN
JOHNY
JANARDHAN
Output:
JJOJAN
OHHARD
NNYHAN
Example Input/Output 2:
Input:
4
JOHN
JOHNY
JANARDHAN
MIKESPENCER
Output:
JJOJANMIKE
OHHARDSPE
NNYHANNCER
C++ Program:
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
string s,s1="",s2="",s3="";
int n;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>s;
    s1+=s.substr(0,i+1);
    s2+=s.substr(i+1,s.length()-2*(i+1));
    s3+=s.substr(s.length()-(i+1));
}
cout<<s1<<"\n"<<s2<<"\n"<<s3;
}

No comments:

Post a Comment