main #1

Merged
Mikhail merged 2 commits from main into name_of_branch 2 years ago
  1. 41
      польский калькулятор.txt
  2. 26
      удаление пробелов.txt

@ -0,0 +1,41 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str;
getline(cin, str);
vector <char> sym;
vector <int> ans;
int a;
for (int i = 0; i < str.size(); i++){
if (str[i] != ' ') {
sym.push_back(str[i]);
}
}
for (int i = 0; i < sym.size(); i++) {
if ('0' <= sym[i] && sym[i] <= '9') {
ans.push_back(sym[i] - '0');
}
if (sym[i] == '+') {
a = ans[ans.size() - 1];
ans.pop_back();
ans[ans.size() - 1] += a;
}
if (sym[i] == '-') {
a = ans[ans.size() - 1];
ans.pop_back();
ans[ans.size() - 1] -= a;
}
if (sym[i] == '*') {
a = ans[ans.size() - 1];
ans.pop_back();
ans[ans.size() - 1] *= a;
}
}
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << ' ';
return 0;
}

@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str;
getline(cin, str);
int flag = 0;
for (int i = 0; i < str.size(); i++){
if (str[i] != ' ') {
cout << str[i];
flag = 1;
}
if (str[i] == ' ' && flag == 0) {
continue;
}
if (str[i] == ' ' && i+1 < str.size() && flag == 1) {
if (str[i+1] != ' ') {
cout << str[i];
}
}
}
return 0;
}
Loading…
Cancel
Save