-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathArithmeticExpressions.cpp
37 lines (29 loc) · 1.15 KB
/
ArithmeticExpressions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <cstdio>
#include <vector>
int main(){
const long M = 101;
long n; scanf("%ld", &n);
std::vector<long> a(n); for(long p = 0; p < n; p++){scanf("%ld", &a[p]);}
std::vector<std::vector<char> > s(M);
std::vector<bool> f(M, 0); f[a[0]] = 1;
for(long ind = 1; ind < n; ind++){
std::vector<bool> g(M, 0);
std::vector<std::vector<char> > t(M);
long cur = a[ind];
printf("Ind: %ld %ld\n", ind, cur);
for(long p = 0; p < M; p++){
if(!f[p]){continue;}
printf("%ld -> %ld\n", ind, p);
long u;
u = p + cur; u %= M; if(!g[u]){g[u] = 1; t[u] = s[p]; t[u].push_back('+');}
u = p - cur; u += M; u %= M; if(!g[u]){g[u] = 1; t[u] = s[p]; t[u].push_back('-');}
u = p * cur; u %= M; if(!g[u]){g[u] = 1; t[u] = s[p]; t[u].push_back('*');}
}
f = g; s = t;
}
for(long p = 0; p < M; p++){if(f[p]){printf("Found: %ld\n", p);}}
std::vector<char> list = s[0];
printf("List Size:%ld\n", list.size());
for(long p = 0; p < n - 1; p++){printf("%ld%c", a[p], list[p]);}; printf("%ld\n", a.back());
return 0;
}