Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- void resolver(vector<string> problems) {
- long totalsum = 0;
- bool operador;
- int resparcial = 0;
- string numstr = "";
- vector<int> problem;
- for(int i = problems.front().size() -1; i >= 0 ;--i){
- for(int j = 0; j < problems.size()-1; j++) {
- if (problems[j][i] != ' ') {
- numstr += problems[j][i];
- }
- }
- if (problems[problems.size()-1][i] == '+') {
- if (numstr != "") { // Primer espacio después de leer números
- printf("%i,", stoi(numstr));
- problem.push_back(stoi(numstr));
- numstr = "";
- }
- resparcial = 0;
- for (int& x: problem) {
- resparcial += x;
- }
- printf("+=%i\n",resparcial);
- totalsum+=resparcial;
- numstr = "";
- problem.clear();
- } else if (problems[problems.size()-1][i] == '*'){
- if (numstr != "") { // Primer espacio después de leer números
- printf("%i,", stoi(numstr));
- problem.push_back(stoi(numstr));
- numstr = "";
- }
- resparcial = 1;
- for (int& x: problem) {
- resparcial *= x;
- }
- printf("*=%i\n",resparcial);
- totalsum+=resparcial;
- numstr = "";
- problem.clear();
- } else if (problems[problems.size()-1][i] == ' ') {
- if (numstr != "") { // Primer espacio después de leer números
- printf("%i,", stoi(numstr));
- problem.push_back(stoi(numstr));
- numstr = "";
- }
- }
- }
- printf("%li\n",totalsum);
- }
- int main() {
- string line;
- getline(cin, line);
- vector<string> problems;
- while(line != "") {
- problems.push_back(line);
- getline(cin, line);
- }
- resolver(problems);
- }
Advertisement
Add Comment
Please, Sign In to add comment