In this HackerRank Strings problem in c++, we have given two strings separated by a new line that only consists of lower case Latin characters. so we need to print two separate integers, representing the length of the string in the first line. In the second line, print the string produced by concatenating both strings. in the third line print, two strings are separated by a space.

HackerRank Strings in C++ problem solution

HackerRank Strings in C++ problem solution

#include <iostream>
#include <string>
using namespace std;

int main() {
   // Complete the program
    string a, b;
    cin >> a;
    cin >> b;
    
    int a_len = a.size();
    int b_len = b.size();
    cout << a_len << " " << b_len << endl;
    cout << a+b << endl;
    
    char a_zero = a[0];
    
    a[0] = b[0];
    b[0] = a_zero;
    
    cout << a << " " << b << endl;
    return 0;
}