//Thomas Meeks 6/9/2023
//String demonstration

#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
//algorithm for reverse
//string for stoi, to_string
using namespace std;

//split function, takes a string and a delim returns a vector
//of strings split by that delimeter

//s = "hello-goodbye-whatsup"
//vec res = split(s,'-')
//res = {"hello","goodbye","whatsup"}


//pass in S by reference to make things faster
//we can build the string directly in the res vector for a slightly more
//efficient split function but it's not really neccesary and this is pretty clean.
vector<string> split(const string &s, char delim){
    vector<string> res; //this will be our vector of strings.
    string temp = ""; //we build off this as we go

    //for each loop, c is a character in the string
    for(char c: s){
        //keep building temp
        if(c != delim) temp.push_back(c);
        else{
            //if its equal to our delimeter everything we've built up so far gets
            //pushed to the result
            //and start a new temp;
            res.push_back(temp);
            temp = "";
        }
    }

    //make sure to get the last group of chracters if theres something still in temp
    if(temp.size()) res.push_back(temp);
    return res;
}

int main(){

    //dont need split for this "problem" but its a good example that
    //uses multiple things;
    string s; getline(cin,s);
    //s = "100+17+51"
    vector<string> res = split(s,'+');
    //res = {"100", "17", "51"}
    //we can convert the string to an int with stoi
    int sum = 0;
    for(int i = 0; i < res.size(); i++){
        int val = stoi(res[i]);
        sum+=val;
    }

    cout << sum;
    cout << "\n-----------\n";

    //show concatenation
    string s3, s4; cin >> s3 >> s4;
    string concatenated = s3;
    concatenated+=s4;
    cout << "concatenated " << concatenated << "\n";

    //showing substring, substring takes a start index (0 based) and a length
    string substring = concatenated.substr(2,4);
    cout << "substring of concatenated string " << substring << "\n";
    cout << "Give a number\n";
    int val; cin >> val;
    string valstring = to_string(val);
    cout << "reversing it to show its a string\n";
    reverse(valstring.begin(),valstring.end());
    cout << valstring;

    return 0;
}
