Code For Alls..!

get the code!!

Sunday, 10 September 2017

Isolate Interlaced Strings (Id-3077)

                                               Isolate Interlaced Strings (Id-3077) 



Two string values S1 and S2 are interlaced and passed as a single input string S. Given L1 which is the length of S1, print S1 and S2 as the output.
Input Format:
The first line contains S.
The second line contains L1 and L2 separated by a space.
Output Format:
The first line contains S1.
The second line contains S2.
Boundary Conditions:
4 <= LENGTH(S) <= 100
1 <= LENGTH(S1) <= 99
1 <= LENGTH(S2) <= 99
Example Input/Output 1:
Input:
LBARZIYSK
4
Output:
LAZY
BRISK

c++ program:

#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
string s,f="";
cin>>s;
int n,i;
cin>>n;
for(i=0;i<s.length();i=i+2)
{
    if(f.length()<n)
    {
    f+=s[i];
    s[i]='0';
    }
    if(s.length()-i==n-i/2)
    break;
}
if(i<s.length())
while(i<s.length())
{f+=s[++i];n
s[i]='0';
}
cout<<f<<"\n";
 i=0;
 while(i<s.length())
 {
     if(s[i]!='0')
 cout<<s[i];
 i++;
 }

}

3 comments:

  1. i don't know why two testcases are failed...
    any one know please tell me

    ReplyDelete
  2. make sure these three conditions..
    L1==L2
    L1>L2
    L1<L2

    ReplyDelete