Strings

Sort by

recency

|

760 Discussions

|

  • + 0 comments

    My C++ code 😎🐦‍🔥

    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() {
    	// Complete the program
        string first;
        string second;
        getline(cin,first);
        getline(cin,second);
        
        string third = first + second;
        cout << first.size()<<" "<<second.size()<<endl;
        
        cout<<third<<endl;
        char c = first[0];
        first[0] = second[0];
        second[0] = c;
        cout <<first <<" "<<second<<endl;
      
        return 0;
    }
    
  • + 0 comments

    include

    include

    using namespace std;

    int main() { string a="abcd"; string b="ef";

    cout<<a.length()<<" "<<b.length()<<endl;
    
    string temp=a+b;
    cout<<temp<<endl;
    
    swap(a[0],b[0]);
    cout<<a<<" "<<b;
    
    return 0;
    

    }

  • + 0 comments

    include

    include

    using namespace std;

    int main() { //string a="abcd"; //string b="ef"; string a; string b; cin>>a; cin>>b; cout<

    return 0;
    

    1. }

  • + 0 comments

    int main() { std::string a; std::string b; std::cin>>a; std::cin>>b;

    std::cout<<a.size()<<" "<<b.size()<<std::endl;
    std::cout<<a+b<<std::endl;
    
    std::string first_char_of_a = {a[0]};
    std::string second_char_of_b = {b[0]};
    
    std::cout<<a.replace(0,1, second_char_of_b)<<" "<<b.replace(0,1,first_char_of_a)<<std::endl;
    
    return 0;
    

    }

  • + 0 comments
    #include <iostream>
    #include <sstream>
    
    std::string getInput() {
        std::string inputt{};
        std::cin >> inputt;
        return inputt;
    }
    
    int main() {
       std::string first_val{getInput()};
       std::string second_val{getInput()};
       std::string first_char_of_first_value {first_val[0]};
       std::string second_char_of_first_value {second_val[0]};
       std::cout << first_val.length() << " " << second_val.length() << '\n';
       std::cout << first_val+second_val << '\n';
       std::cout << first_val.replace(0,1,second_char_of_first_value) << " " << second_val.replace(0,1,first_char_of_first_value) << '\n';
    
        return 0;
    }