Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************/
- /* LEN’ BULO */
- /* DODELIVAT’ */
- /* i YA OStavil’ */
- /* TAK */
- /* P.S. poslanuye ko mne */
- /* v Byduyshem dodelat’ */
- /* etot project */
- /**************************/
- #include <iostream>
- #include <vector>
- #include <string>
- #include <math.h>
- #include <map>
- #include <algorithm>
- using namespace std;
- void printVector(const vector<int>& v) {
- std::cout << endl;
- cout << "Вывод вектора : " << endl;
- for (auto i : v) {
- cout << i << ' ';
- }
- }
- void printMap(const map<int, char>& v) {
- cout << endl;
- cout << "Вывод Map : " << endl;
- for (auto item : v) {
- cout << "element: " << item.first << " : " << item.second << endl;
- }
- }
- void lastPrintVector(const vector<int>& v) {
- cout << endl;
- cout << "Вывод последнего вектора : " << endl;
- for (auto i : v) {
- cout << i << ' ';
- }
- }
- int Swap(vector<int>& num, vector<int>& numv2) {
- int temp = 0;
- for (int i = 0; i < numv2.size(); i++) {
- num.push_back(numv2[i]);
- }
- numv2.clear();
- return 0;
- }
- void calc(string a) {
- vector<int> element{ 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 };
- vector<int> num, numv2, pluse, minus;
- map<int, char>symbole;
- int temp = 0, temp1 = 0, temp2 = 0, set = 0, plus = 0, minusm = 0;
- for (int i = 0; i < a.size(); i++) {
- if (a[i] == '-' && a[i + 1] > 0) {
- for (int d = 0; d < a.size(); d++) {
- if (a[d+1] != '+' && a[d+1] != '-' && a[d+1] != '*') {
- if (a[d+1] == '1') {
- temp = -1;
- minus.push_back(temp);
- }
- if (a[d+1] == '2') {
- temp = -2;
- minus.push_back(temp);
- }
- if (a[d+1] == '3') {
- temp = -3;
- minus.push_back(temp);
- }
- if (a[d+1] == '4') {
- temp = -4;
- minus.push_back(temp);
- }
- if (a[d+1] == '5') {
- temp = -5;
- minus.push_back(temp);
- }
- if (a[d+1] == '6') {
- temp = -6;
- minus.push_back(temp);
- }
- if (a[d+1] == '7') {
- temp = -7;
- minus.push_back(temp);
- }
- if (a[d+1] == '8') {
- temp = -8;
- minus.push_back(temp);
- }
- if (a[d+1] == '9') {
- temp = -9;
- minus.push_back(temp);
- }
- }
- else {
- reverse(minus.begin(), minus.end());
- for (int k = 0; k < minus.size(); k++) {
- temp = minus[k] * element[k];
- temp1 += temp;
- cout << "\nTEMP! MINUS: " << temp1;
- }
- num.push_back(temp1);
- cout << "\nTEMP2 MINUS: " << temp1;
- temp = temp1 = 0;
- break;
- }
- }
- }
- if (a[i] == '1') {
- temp = 1;
- num.push_back(temp);
- }
- if (a[i] == '2') {
- temp = 2;
- num.push_back(temp);
- }
- if (a[i] == '3') {
- temp = 3;
- num.push_back(temp);
- }
- if (a[i] == '4') {
- temp = 4;
- num.push_back(temp);
- }
- if (a[i] == '5') {
- temp = 5;
- num.push_back(temp);
- }
- if (a[i] == '6') {
- temp = 6;
- num.push_back(temp);
- }
- if (a[i] == '7') {
- temp = 7;
- num.push_back(temp);
- }
- if (a[i] == '8') {
- temp = 8;
- num.push_back(temp);
- }
- if (a[i] == '9') {
- temp = 9;
- num.push_back(temp);
- }
- if (a[i] == '0') {
- temp = 0;
- num.push_back(temp);
- }
- if (a[i] == '+') {
- symbole[i] = '+';
- pluse.push_back(i);
- reverse(num.begin(), num.end());
- for (int k = 0; k < num.size(); k++) {
- temp = num[k] * element[k];
- temp1 += temp;
- }
- numv2.push_back(temp1);
- temp = temp1 = 0;
- num.clear();
- }
- if (a[i] == '-') {
- symbole[i] = '-';
- for (int minusmin = 0; minusmin < minusm; minusmin++) {
- symbole.erase(symbole.begin());
- }
- reverse(num.begin(), num.end());
- for (int k = 0; k < num.size(); k++) {
- temp = num[k] * element[k];
- temp1 += temp;
- }
- numv2.push_back(temp1);
- temp = temp1 = 0;
- num.clear();
- }
- if (a[i] == '*') {
- symbole[i] = '*';
- reverse(num.begin(), num.end());
- for (int k = 0; k < num.size(); k++) {
- temp = num[k] * element[k];
- temp1 += temp;
- }
- numv2.push_back(temp1);
- temp = temp1 = 0;
- num.clear();
- }
- }
- reverse(num.begin(), num.end());
- for (int k = 0; k < num.size(); k++){
- temp = num[k] * element[k];
- temp1 += temp;
- }
- numv2.push_back(temp1);
- temp = temp1 = 0;
- num.clear();
- Swap(num, numv2);
- cout << endl;
- int i = 0;
- temp = 0;
- numv2.clear();
- printMap(symbole);
- for (auto item : symbole) {
- if (item.second == '*') {
- vector <int>::iterator it;
- it = (num.begin());
- int temp4 = num.size();
- //if ((temp4 % 2) != 0) { num.push_back(0); minusm++; }//добавляем 1 блок если число не полное
- int sizenumv2 = (num.size() / 2);// узнаем кол. ячеек
- temp1 = num[0];
- temp2 = num[1];
- num.erase(num.begin());
- num.erase(num.begin());
- cout << "\ntemp1 == " << temp1 << " temp2 == " << temp2 << endl;
- temp = temp1 * temp2;
- num.emplace(it, temp);
- lastPrintVector(num);
- if (num.size() == 0) {
- break;
- }
- }
- }
- for (auto item : symbole) {
- if (item.second == '+') {
- vector <int>::iterator it;
- it = (num.begin());
- int temp4 = num.size();
- //if ((temp4 % 2) != 0) { num.push_back(0); minusm++; }//добавляем 1 блок если число не полное
- int sizenumv2 = (num.size() / 2);// узнаем кол. ячеек
- temp1 = num[0];
- temp2 = num[1];
- num.erase(num.begin());
- num.erase(num.begin());
- cout << "\ntemp1 == " << temp1 << " temp2 == " << temp2 << endl;
- temp = temp1 + temp2;
- num.emplace(it, temp);
- lastPrintVector(num);
- if (num.size() == 0) {
- break;
- }
- }
- if (item.second == '-') {
- vector <int>::iterator it;
- it = (num.begin());
- int temp4 = num.size();
- //if ((temp4 % 2) != 0) { num.push_back(0); minusm++; }//добавляем 1 блок если число не полное
- int sizenumv2 = (num.size() / 2);// узнаем кол. ячеек
- temp1 = num[0];
- temp2 = num[1];
- num.erase(num.begin());
- num.erase(num.begin());
- cout << "\ntemp1 == " << temp1 << " temp2 == " << temp2 << endl;
- temp = temp1 - temp2;
- num.emplace(it, temp);
- lastPrintVector(num);
- if (num.size() == 0) {
- break;
- }
- }
- }
- cout << endl;
- cout << "Конечный вывод" << " : " << temp << endl;
- }
- int main(){
- setlocale(LC_ALL, "Russian");
- string num;
- cin >> num;
- calc(num);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement