Skip to content

Instantly share code, notes, and snippets.

@nukopy
Created February 10, 2019 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nukopy/406b22b7280d57cf51835e1b4a6d77c9 to your computer and use it in GitHub Desktop.
Save nukopy/406b22b7280d57cf51835e1b4a6d77c9 to your computer and use it in GitHub Desktop.
ABC033 - C: 数式の書き換え
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll ctoi(char c){
if('0' <= c && c <= '9') return (c-'0');
return -1;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// input
string str;
cin >> str;
// + と * だけ
size_t len = str.length();
if (len == 1) {
if (str[0] == '0') cout << 0 << "\n";
else cout << 1 << "\n";
} else {
vector<ll> nums;
vector<char> ope;
for (ll i = 0; i < len; ++i) {
if (i % 2 == 0) nums.push_back(ctoi(str[i]));
else ope.push_back(str[i]);
}
vector<ll> vec;
vec.push_back(nums[0]);
ll idx = 0;
ll num;
for (ll i = 1; i < nums.size(); ++i) {
num = (nums[i] != 0)? 1: 0;
if (ope[i - 1] == '*') {
// vec[idx] = vec[idx] * nums[i];
vec[idx] = vec[idx] * num;
} else {
// vec.push_back(nums[i]);
vec.push_back(num);
idx++;
}
}
ll sum = 0;
for (ll i = 0; i < vec.size(); ++i) {
if (vec[i] != 0) sum++;
}
cout << sum << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment