Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  C:
Language: C/C++
Code:
#include <string>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    string strNumber;
    vector<int> input;
    (getline(cin, strNumber, '='));
    int num = stoi(strNumber);
    input.push_back(num);
    string strNumber1;
    while ((getline(cin, strNumber1, '+'))) {
        int num = stoi(strNumber1);
        input.push_back(num);
    }
    if(input[0] == input[input.size()-1]){
        cout << "No solution";
    }
    else if(input[input.size()-1] == input[input.size()-2]){
        input[input.size()-2] += input[input.size()-1];
        input[input.size()-1] = 0;
        for(int i = 0; i < input.size()-1; i++){
            if(i == 0){
                cout << input[0] << "=";
            }
            else if(input[i+1] == 0){
                cout << input[i];
            }
            else{
                cout << input[i] << "+";
            }
        }
    }
    else if(input[input.size()-1] > input[input.size()-2]){
        input[input.size()-2] += 1;
        input[input.size()-1] -= 1;
        for(int i = 0; i < input.size(); i++){
            if(i == 0){
                cout << input[0] << "=";
            }
            else if(i == input.size()-1){
                cout << input[i];
            }
            else{
                cout << input[i] << "+";
            }
        }
    }
    return 0;
}     
Comments: