-1
#include<iostream>
#include<string>
using namespace std;
int main ()
{
    string str;
    string str2;
    int count;
    cin>>count;
    while(count!=0)
    {
        cin>>str;
        cin>>str2;
        int l=str2.length()-1;
        cout<<str[0];
        if(str.length()==str2.length())
        {
        for(int x=1;x<str.length();x++)
            cout<<str2[x-1]<<(str[x]);
            cout<<str2[l];
            cout<<endl;
        }
        count--;
    }



    return 0;
}

Given two strings S and T. Print a new string that contains the following:

The first letter of the string S followed by the first letter of the string T.

the second letter of the string S followed by the second letter of the string T.

and so on...

In other words, the new string should be ( S0 + T0 + S1 + T1 + .... ). Note: If the length of S is greater than the length of T then you have to add the rest of S letters at the end of the new string and vice versa.

Input

The first line contains a number N (1 ≤ N ≤ 50) the number of test cases.

Each of the N following lines contains two string S, T (1 ≤ |S|, |T| ≤ 50) consists of lower and upper English letters.

Output

For each test case, print the required string.

Example

inputCopy
2
ipAsu ccsit
ey gpt
outputCopy
icpcAssiut
egypt

in my good i get errors in some cases can someone tell me how to solve this probelm

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • 3
    You'll be glad to hear you don't need anyone's help to figure this out, just a tool you already have: your debugger! This is exactly what a debugger is for. It [runs your program, one line at a time, and shows you what's happening](https://stackoverflow.com/questions/25385173/), this is something that's every C++ developer must know how to do. With your debugger's help you'll able to quickly find all problems in this and all future programs you write, without having to ask anyone for help. Have you tried using your debugger, already? If not, why not? What did your debugger show you? – Sam Varshavchik Dec 16 '21 at 15:28
  • 3
    My advice, learn how to use a debugger, then you can go through your code step by step and check the content of memory at each step and verify it is what you think it should be. – Pepijn Kramer Dec 16 '21 at 15:28
  • Why are you repeatidly adding `str2[l];`? – Damien Dec 16 '21 at 15:35

2 Answers2

0

Notice the Note given above:

Note: If the length of S is greater than the length of T then you have to add the rest of S letters at the end of the new string and vice versa.

Your code runs well in terms of two same-length strings. However, cause "if(str.length()==str2.length())" in your code, your program will only output one character! Example: given "acd" and "b", your answer is "a", but "abcd" is expected.

0

A straightforward approach can look the following way

std::string::size_type i = 0;

for ( auto n = std::min( str.size(), str2.size() ); i < n; i++ )
{
    std::cout << str[i] << str2[i];
}

while ( i < str.size() )
{
    std::cout << str[i++];
}

while ( i < str2.size() )
{
    std::cout << str2[i++];
}    

Here is a demonstration program

#include <iostream>
#include <string>
#include <algorithm>

int main()
{
    std::string str( "ipAsu" );
    std::string str2( "ccsit" );

    std::string::size_type i = 0;

    for (auto n = std::min( str.size(), str2.size() ); i < n; i++)
    {
        std::cout << str[i] << str2[i];
    }

    while (i < str.size())
    {
        std::cout << str[i++];
    }

    while (i < str2.size())
    {
        std::cout << str2[i++];
    }

    std::cout << '\n';
}

The program output is

icpcAssiut

You could move the basic code in a separate function.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335