Recent Post

Strings.cpp-HackerRank

Problem-Input Format

You are given two strings,  and , separated by a new line. Each string will consist of lower case Latin characters ('a'-'z').

Output Format

In the first line print two space-separated integers, representing the length of  and  respectively.
In the second line print the string produced by concatenating  and  ().
In the third line print two strings separated by a space,  and .  and  are the same as  and , respectively, except that their first characters are swapped.


Solution-
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int c=a.size();
    int d=b.size();
    cout<<c<<" "<<d<<endl;
    string s=a+b;
    cout<<s<<endl;
    char temp;
    temp=a[0];
    a[0]=b[0];
    b[0]=temp;
    cout<<a<<" "<<b;
}

Link to the problem:-

Result!

Comments

Popular posts from this blog

Caesar Cipher.c-HackerRank

Bon Appétit.c-HackerRank

Electronics Shop.c-HackerRank