I received an automated message from HackerRank with a challenge based on strings. I incorrectly assumed it was the next one in the Introduction section of C++. After solving it I found I made an incorrect assumption. Such is life.
If interested, the challenge description may be found at: https://www.hackerrank.com/challenges/c-tutorial-strings?utm_campaign=challenge-recommendation&utm_medium=email&utm_source=24-hour-campaign
Following is the contents of a Windows console created by Microsoft Visual Studio Professional 2013 IDE using the sample data for the challenge:
abcd
ef
4 2
abcdef
ebcd af
The output matched the test. Submitted my solution and passed all six test cases.
My solution in C++ follows:
#include <iostream>
#include <string>
using namespace std;
/*
*/
int main () {
string a,
b;
// **** ****
cin >> a;
cin >> b;
cout << a.size() << ” ” << b.size() << endl;
cout << a + b << endl;
char temp = a[0];
a[0] = b[0];
b[0] = temp;
cout << a << ” ” << b << endl;
// **** ****
return 0;
}
If you have a comment or questions regarding this or any other post in this blog, please send me a message via email. I will not use your name unless you explicitly allow me to do so.
John
john.canessa@gmail.com
Follow me on Twitter: @john_canessa