Strings

  • + 0 comments

    Here is my code, bit simple, easy to understand.

    #include <cmath>
    #include <cstdio>
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    int main() {
        // Assign strings a and b
         string a;
         string b;
         
         // Get the input
         getline(cin, a);
         getline(cin, b);
         
         // Find the length
         int len1 = a.size();
         int len2 = b.size();
         
         // Output length and concatenation
         cout << len1 << " " << len2 << endl;
         cout << a + b << endl;
         
         // Work on swapping the characters
         char tempChar = a[0];
         a[0] = b[0];
         b[0] = tempChar;
         
         // Output swapped characters
         cout << a << " " << b;
        return 0;
    }