Strings

  • + 0 comments
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main() {
        string a, b;
        cin >> a >> b;
    
        // First line: lengths of a and b
        cout << a.length() << " " << b.length() << endl;
    
        // Second line: concatenated string
        cout << a + b << endl;
    
        // Third line: swap first characters of a and b
        char temp = a[0];
        a[0] = b[0];
        b[0] = temp;
    
        cout << a << " " << b << endl;
    
        return 0;
    }