-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy path11_iLoveStrings.cpp
50 lines (47 loc) · 1.44 KB
/
11_iLoveStrings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int main()
{
// taking no of test cases input
int test_case;
cin >> test_case;
while (test_case--)
{
string str1, str2;
cin >> str1 >> str2; // taking inputs from user
int size1 = str1.size();
int size2 = str2.size();
int i = 0; // pointer pointing to zeroth index
string str3 = ""; // empty new string
// first we iterate in each string upto the size of the minimum of the two strings
for (; i < min(size1, size2); i++) //
{
str3 += str1[i]; // concating from string1
str3 += str2[i]; // concating from string2
}
if (size1 == size2)
cout << str3 << endl;
else
{
//if the pointer reaches the size of string 1 i.e string 1 is iterated
//so we concatenate the remaining of string2 in the new string
if (i == size1)
{
for (; i < size2; i++)
{
str3 += str2[i];
}
}
//if the pointer reaches the size of string 2 i.e string 2 is iterated
//so we concatenate the remaining of string1 in the new string
else
{
for (; i < size1; i++)
{
str3 += str1[i];
}
}
cout << str3 << endl;
}
}
}