Strings

Sort by

recency

|

765 Discussions

|

  • + 0 comments

    include

    using namespace std;

    int main(){ string a,b; cin >> a >> b; cout << a.size() << " " << b.size() << endl; cout << a+b << endl; swap(a[0], b[0]); cout << a << " " << b << endl; return 0; }

  • + 0 comments

    include

    include

    using namespace std;

    int main() { string a,b; cin>>a>>b; cout<

    }

  • + 0 comments

    include

    include

    using namespace std;

    int main() { // Complete the program string a , b ; cin>>a>>b; cout<

    return 0;
    

    }

  • + 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;
    }
    
  • + 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;
    }