buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> constexpr int MOD = 1000000007; constexpr int INF = 2000000000; using namespace std; int main() { int a, b, c; int A[101], B[101], C[101], D[101]; int ans[301]; int n; while (cin >> a >> b >> c && a != 0 && b != 0 && c != 0) { cin >> n; for (int i = 1; i <= a + b + c; i++) { ans[i] = 2; } for (int i = 0; i < n; i++) { cin >> A[i] >> B[i] >> C[i] >> D[i]; if (D[i] == 1) { ans[A[i]] = ans[B[i]] = ans[C[i]] = 1; } } for (int i = 0; i < n; i++) { if (D[i] == 0) { if (ans[A[i]] == 2 && ans[B[i]] == 1 && ans[C[i]] == 1) ans[A[i]] = 0; if (ans[A[i]] == 1 && ans[B[i]] == 2 && ans[C[i]] == 1) ans[B[i]] = 0; if (ans[A[i]] == 1 && ans[B[i]] == 1 && ans[C[i]] == 2) ans[C[i]] = 0; } } for (int i = 1; i <= a + b + c; i++) cout << ans[i] << endl; } }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> constexpr int MOD = 1000000007; constexpr int INF = 2000000000; using namespace std; int main() { int a, b, c; int A[1001], B[1001], C[1001], D[1001]; int ans[10001]; int n; while (cin >> a >> b >> c && a != 0 && b != 0 && c != 0) { cin >> n; for (int i = 1; i <= a + b + c; i++) { ans[i] = 2; } for (int i = 0; i < n; i++) { cin >> A[i] >> B[i] >> C[i] >> D[i]; if (D[i] == 1) { ans[A[i]] = ans[B[i]] = ans[C[i]] = 1; } } for (int i = 0; i < n; i++) { if (D[i] == 0) { if (ans[A[i]] == 2 && ans[B[i]] == 1 && ans[C[i]] == 1) ans[A[i]] = 0; if (ans[A[i]] == 1 && ans[B[i]] == 2 && ans[C[i]] == 1) ans[B[i]] = 0; if (ans[A[i]] == 1 && ans[B[i]] == 1 && ans[C[i]] == 2) ans[C[i]] = 0; } } for (int i = 1; i <= a + b + c; i++) cout << ans[i] << endl; } }
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
1
395
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define MOD 1000000007 #define rep(i, n) for (i = 0; i < n; i++) #define loop(i, a, n) for (i = a; i < n; i++) #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) typedef vector<int> vi; typedef pair<int, int> pii; int main(void) { int i, j; int a, b, c, n; while (1) { cin >> a >> b >> c; if (a + b + c == 0) break; cin >> n; vi v(a + b + c, 2); vi p, q, r; rep(i, n) { int tp, tq, tr, ts; cin >> tp >> tq >> tr >> ts; tp--; tq--; tr--; if (ts) { v[tp] = v[tq] = v[tr] = 1; // ok } else { p.push_back(tp); q.push_back(tq); r.push_back(tr); } } rep(i, p.size()) { if (v[p[i]] == 1 && v[q[i]] == 1) v[r[i]] = 0; // false if (v[p[i]] == 1 && v[r[i]] == 1) v[q[i]] = 0; // false if (v[r[i]] == 1 && v[q[i]] == 1) v[q[i]] = 0; // false } rep(i, a + b + c) cout << v[i] << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define MOD 1000000007 #define rep(i, n) for (i = 0; i < n; i++) #define loop(i, a, n) for (i = a; i < n; i++) #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) typedef vector<int> vi; typedef pair<int, int> pii; int main(void) { int i, j; int a, b, c, n; while (1) { cin >> a >> b >> c; if (a + b + c == 0) break; cin >> n; vi v(a + b + c, 2); vi p, q, r; rep(i, n) { int tp, tq, tr, ts; cin >> tp >> tq >> tr >> ts; tp--; tq--; tr--; if (ts) { v[tp] = v[tq] = v[tr] = 1; // ok } else { p.push_back(tp); q.push_back(tq); r.push_back(tr); } } rep(i, p.size()) { if (v[p[i]] == 1 && v[q[i]] == 1) v[r[i]] = 0; if (v[p[i]] == 1 && v[r[i]] == 1) v[q[i]] = 0; if (v[r[i]] == 1 && v[q[i]] == 1) v[p[i]] = 0; } rep(i, a + b + c) cout << v[i] << endl; } }
[["-", 0, 11, 31, 69, 341, 342, 0, 69, 28, 22], ["+", 0, 11, 31, 69, 341, 342, 0, 69, 28, 22]]
1
380
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; int main() { while (1) { int a, b, c, q, w, e[300], l[1000][4], n; cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) break; cin >> n; for (q = 0; q < a + b + c; q++) e[q] = 2; for (q = 0; q < n; q++) { cin >> l[q][0] >> l[q][1] >> l[q][2] >> l[q][3]; if (l[q][3] == 1) { e[l[q][0]] = 1; e[l[q][1]] = 1; e[l[q][2]] = 1; } } for (q = 0; q < n; q++) { for (w = 0; w < n; w++) { if (l[w][3] == 0 && e[l[w][0]] == 1 && e[l[w][1]] == 1) e[l[w][2]] = 0; if (l[w][3] == 0 && e[l[w][2]] == 1 && e[l[w][1]] == 1) e[l[w][0]] = 0; if (l[w][3] == 0 && e[l[w][0]] == 1 && e[l[w][2]] == 1) e[l[w][1]] = 0; } } for (q = 0; q < a + b + c; q++) cout << e[q] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; int main() { while (1) { int a, b, c, q, w, e[301], l[1000][4], n; cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) break; cin >> n; for (q = 1; q <= a + b + c; q++) e[q] = 2; for (q = 0; q < n; q++) { cin >> l[q][0] >> l[q][1] >> l[q][2] >> l[q][3]; if (l[q][3] == 1) { e[l[q][0]] = 1; e[l[q][1]] = 1; e[l[q][2]] = 1; } } for (q = 0; q < n; q++) { for (w = 0; w < n; w++) { if (l[w][3] == 0 && e[l[w][0]] == 1 && e[l[w][1]] == 1) e[l[w][2]] = 0; if (l[w][3] == 0 && e[l[w][2]] == 1 && e[l[w][1]] == 1) e[l[w][0]] = 0; if (l[w][3] == 0 && e[l[w][0]] == 1 && e[l[w][2]] == 1) e[l[w][1]] = 0; } } for (q = 1; q <= a + b + c; q++) cout << e[q] << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
414
def func(n,k): SUM = 0 ans = 0 A = [int(input()) for _ in range(n)] for i in range(k-1): SUM += A[i] for i in range(k,len(A)): ans = max(ans,SUM+A[i]-A[i-k]) SUM = SUM+A[i]-A[i-k] print(ans) for _ in range(10): n,k = [int(s) for s in input().split()] if n == 0 and k ==0: break else: func(n,k)
def func(n,k): SUM = 0 ans = 0 A = [int(input()) for _ in range(n)] for i in range(k): SUM += A[i] for i in range(k,len(A)): ans = max(ans,SUM+A[i]-A[i-k]) SUM = SUM+A[i]-A[i-k] print(ans) for _ in range(10): n,k = [int(s) for s in input().split()] if n == 0 and k ==0: break else: func(n,k)
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 17, 33], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
145
def main(): while True: a = [] n, k = [int(x) for x in input().split()] if n == 0 and k == 0: break for i in range(n): a.append(int(input())) l = [0] for i in range(1, n - k + 1): l.append(a[i + k - 1] - a[i - 1]) maxsum = 0 maxi = 0 s = 0 for i, x in enumerate(l): s += x if s >= maxsum: maxsum = s maxi = i print(sum(a[i - 1:i + k - 1])) main()
def main(): while True: a = [] n, k = [int(x) for x in input().split()] if n == 0 and k == 0: break for i in range(n): a.append(int(input())) l = [0] for i in range(1, n - k + 1): l.append(a[i + k - 1] - a[i - 1]) maxsum = 0 maxi = 0 s = 0 for i, x in enumerate(l): s += x if s >= maxsum: maxsum = s maxi = i print(sum(a[maxi:maxi + k])) main()
[["-", 3, 4, 0, 206, 206, 663, 0, 657, 31, 22], ["-", 3, 4, 0, 206, 206, 663, 0, 657, 17, 33], ["-", 3, 4, 0, 206, 206, 663, 0, 657, 12, 612], ["+", 0, 652, 3, 4, 0, 206, 206, 663, 0, 22], ["-", 0, 206, 206, 663, 0, 657, 31, 657, 31, 22], ["+", 3, 4, 0, 206, 206, 663, 0, 657, 31, 22]]
5
154
#include <stdio.h> int smax(int *list, int n) { int max, sec, maxreal, i; max = sec = maxreal = 0; for (i = 0; i < n; i++) if (list[i] == 1) { max++; sec++; } else if (list[i] == 0) if (max > maxreal) { maxreal = max; max = sec + 1; sec = 0; } else { max = sec + 1; sec = 0; } if (max > maxreal) maxreal = max; return maxreal; } int nmax(int *list, int n) { int max, sec, maxreal, i; max = sec = 0; for (i = 0; i < n; i++) if (list[i] == 1) { sec++; } else { if (max < sec) { max = sec; sec = 0; } } if (max < sec) max = sec; return max; } int main() { int list[100000]; int i, n, k, flag, tmp, max, j; while (1) { flag = 0; scanf("%d %d", &n, &k); if (n == 0 && k == 0) break; for (i = 0; i < 100000; i++) list[i] = 0; for (i = 0; i < k; i++) { scanf("%d", &tmp); if (tmp == EOF) break; if (tmp > 0) list[tmp - 1] = 1; else flag = 1; /* for(j=0;j<n;j++) printf("%d\n",list[j]); printf("--------\n"); */ } if (flag == 1) printf("%d\n", smax(list, n)); else printf("%d\n", nmax(list, n)); } return 0; }
#include <stdio.h> int smax(int *list, int n) { int max, sec, maxreal, i; // maxreal is output. max = sec = maxreal = 0; for (i = 0; i < n; i++) if (list[i] == 1) { max++; sec++; } else if (list[i] == 0) if (max >= maxreal) { maxreal = max; max = sec + 1; sec = 0; } else { max = sec + 1; sec = 0; } if (max > maxreal) maxreal = max; return maxreal; } int nmax(int *list, int n) { int max, sec, maxreal, i; max = sec = 0; for (i = 0; i < n; i++) { if (list[i] == 1) { sec++; } else { if (max < sec) max = sec; sec = 0; } } if (max < sec) max = sec; return max; } int main() { int list[100000]; int i, n, k, flag, tmp, max, j; while (1) { flag = 0; scanf("%d %d", &n, &k); if (n == 0 && k == 0) break; for (i = 0; i < 100000; i++) list[i] = 0; for (i = 0; i < k; i++) { scanf("%d", &tmp); if (tmp == EOF) break; if (tmp > 0) list[tmp - 1] = 1; else flag = 1; /* for(j=0;j<n;j++) printf("%d\n",list[j]); printf("--------\n"); */ } if (flag == 1) printf("%d\n", smax(list, n)); else printf("%d\n", nmax(list, n)); } return 0; }
[["-", 0, 57, 64, 57, 15, 23, 0, 16, 17, 47], ["+", 0, 57, 64, 57, 15, 23, 0, 16, 17, 20], ["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 45], ["-", 75, 76, 0, 9, 0, 57, 64, 9, 0, 45]]
0
381
#include "bits/stdc++.h" //#define int long long using namespace std; #define REP(i, s, n) for (signed i = (s); i < signed(n); i++) #define rep(i, n) REP(i, 0, n) #define all(co) co.begin(), co.end() typedef pair<int, int> P; typedef unsigned long long LL; #ifdef int const long long INF = 1ll << 61ll; #else const signed INF = 1 << 29; #endif template <typename T = int> vector<vector<T>> vvector(int h, int w, T def = T()) { return move(vector<vector<T>>(h, vector<T>(w, def))); } signed main() { int n, k; while (cin >> n >> k && n) { n++; vector<int> dp(n + 2); bool white = false; rep(i, k) { int x; cin >> x; if (x) dp[x] = 1; else white = true; } rep(i, n) if (dp[i + 1]) dp[i + 1] = dp[i + 1] + dp[i]; rep(i, n) if (dp[n - i]) dp[n - i] = max(dp[n - i], dp[n - i + 1]); int ans = 0; rep(i, n - 1) ans = max( ans, (white && !dp[i + 1] ? dp[i] + dp[i + 1] + dp[i + 2] : dp[i + 1])); cout << ans << endl; } return 0; }
#include "bits/stdc++.h" //#define int long long using namespace std; #define REP(i, s, n) for (signed i = (s); i < signed(n); i++) #define rep(i, n) REP(i, 0, n) #define all(co) co.begin(), co.end() typedef pair<int, int> P; typedef unsigned long long LL; #ifdef int const long long INF = 1ll << 61ll; #else const signed INF = 1 << 29; #endif template <typename T = int> vector<vector<T>> vvector(int h, int w, T def = T()) { return move(vector<vector<T>>(h, vector<T>(w, def))); } signed main() { int n, k; while (cin >> n >> k && n) { n++; vector<int> dp(n + 2); bool white = false; rep(i, k) { int x; cin >> x; if (x) dp[x] = 1; else white = true; } rep(i, n) if (dp[i + 1]) dp[i + 1] = dp[i + 1] + dp[i]; rep(i, n) if (dp[n - i]) dp[n - i] = max(dp[n - i], dp[n - i + 1]); int ans = 0; rep(i, n - 1) ans = max(ans, (white && !dp[i + 1] ? dp[i] + dp[i + 1] + dp[i + 2] + 1 : dp[i + 1])); cout << ans << endl; } return 0; }
[["+", 3, 4, 0, 23, 0, 41, 64, 16, 17, 72], ["+", 3, 4, 0, 23, 0, 41, 64, 16, 12, 13]]
1
342
#include <bits/stdc++.h> using namespace std; #define FOR(i, s, n) for (int i = s; i < (int)n; i++) #define per(i, n) for (int i = n; i >= 0; i--) #define ROF(i, s, n) for (int i = s; i >= (int)n; i--) #define FORIT(i, A) for (auto i : A) #define PRINT(x) cout << (x) << "\n" #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define MP make_pair #define EACH(i, n) \ for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i) #define SZ(a) int((a).size()) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define CLR(a) memset((a), 0, sizeof(a)) #define NCLR(a) memset((a), -1, sizeof(a)) #define dump(x) cout << #x << " = " << (x) << "\n"; #define debug(x) \ cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << "\n"; #define sq(n) (n) * (n) typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef unsigned int uint; typedef unsigned long long ull; typedef priority_queue<int> maxpq; typedef priority_queue<int, vector<int>, greater<int>> minpq; typedef complex<double> P; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const int mod = 1000000007; static const int INF = 1 << 29; static const LL LL_INF = 1152921504606846976; static const int dx[] = {-1, 0, 1, 0, 1, -1, 1, -1}; static const int dy[] = {0, -1, 0, 1, 1, 1, -1, -1}; int n, m; bool can_use; set<int> a; int dp[100001][2]; int ans = 0; int solve(int now, bool used) { if (now > n) { return 0; } if (dp[now][used] >= 0) { return dp[now][used]; } int res = 0; if (a.count(now)) { res = max(res, solve(now + 1, used) + 1); } else { if (used) { res = max(res, solve(now + 1, used - 1) + 1); } else { return dp[now][used] = 0; } } return dp[now][used] = res; } int main() { while (~scanf("%d %d", &n, &m) && n && m) { NCLR(dp); can_use = false; for (int i = 0; i < m; i++) { int b; scanf("%d", &b); if (b) { a.insert(b); } else { can_use = true; } } ans = 0; for (int i = 1; i <= n; i++) { if (a.count(i - 1) == 1 && a.count(i)) { continue; } ans = max(ans, solve(i, can_use)); } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, s, n) for (int i = s; i < (int)n; i++) #define per(i, n) for (int i = n; i >= 0; i--) #define ROF(i, s, n) for (int i = s; i >= (int)n; i--) #define FORIT(i, A) for (auto i : A) #define PRINT(x) cout << (x) << "\n" #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define MP make_pair #define EACH(i, n) \ for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i) #define SZ(a) int((a).size()) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define CLR(a) memset((a), 0, sizeof(a)) #define NCLR(a) memset((a), -1, sizeof(a)) #define dump(x) cout << #x << " = " << (x) << "\n"; #define debug(x) \ cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << "\n"; #define sq(n) (n) * (n) typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef unsigned int uint; typedef unsigned long long ull; typedef priority_queue<int> maxpq; typedef priority_queue<int, vector<int>, greater<int>> minpq; typedef complex<double> P; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const int mod = 1000000007; static const int INF = 1 << 29; static const LL LL_INF = 1152921504606846976; static const int dx[] = {-1, 0, 1, 0, 1, -1, 1, -1}; static const int dy[] = {0, -1, 0, 1, 1, 1, -1, -1}; int n, m; bool can_use; set<int> a; int dp[100001][2]; int ans = 0; int solve(int now, bool used) { if (now > n) { return 0; } if (dp[now][used] >= 0) { return dp[now][used]; } int res = 0; if (a.count(now)) { res = max(res, solve(now + 1, used) + 1); } else { if (used) { res = max(res, solve(now + 1, used - 1) + 1); } else { return dp[now][used] = 0; } } return dp[now][used] = res; } int main() { while (~scanf("%d %d", &n, &m) && n && m) { NCLR(dp); can_use = false; for (int i = 0; i < m; i++) { int b; scanf("%d", &b); if (b) { a.insert(b); } else { can_use = true; } } ans = 0; for (int i = 1; i <= n; i++) { if (a.count(i - 1) == 1 && a.count(i)) { continue; } ans = max(ans, solve(i, can_use)); } printf("%d\n", ans); a.clear(); } return 0; }
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
622
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <sstream> #include <string> #include <vector> using namespace std; int main(void) { int n, k; while (cin >> n >> k, n) { bool a[100020]; for (int i = 0; i < k; i++) { int x; cin >> x; a[x] = true; } int d[100020][2] = {}; for (int i = 1; i <= n; i++) { if (a[i]) { d[i][0] = d[i - 1][0] + 1; d[i][1] = d[i - 1][1] + 1; } else { d[i][1] = d[i - 1][0] + 1; } } int best = 0; for (int i = 1; i <= n; i++) { if (a[0]) { best = max(best, d[i][1]); } best = max(best, d[i][0]); } cout << best << endl; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <sstream> #include <string> #include <vector> using namespace std; int main(void) { int n, k; while (cin >> n >> k, n) { bool a[100020] = {}; for (int i = 0; i < k; i++) { int x; cin >> x; a[x] = true; } int d[100020][2] = {}; for (int i = 1; i <= n; i++) { if (a[i]) { d[i][0] = d[i - 1][0] + 1; d[i][1] = d[i - 1][1] + 1; } else { d[i][1] = d[i - 1][0] + 1; } } int best = 0; for (int i = 1; i <= n; i++) { if (a[0]) { best = max(best, d[i][1]); } best = max(best, d[i][0]); } cout << best << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 45], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 46]]
1
255
#include <bits/stdc++.h> using namespace std; #define rep(i, x) for (int i = 0; i < x; ++i) #define all(a) begin(a), end(a) bool exist[100010]; int len[100010]; int Id[100010]; signed main() { int n, k; while (cin >> n >> k, n) { memset(exist, false, sizeof(exist)); memset(len, 0, sizeof(len)); memset(Id, 0, sizeof(Id)); bool f = false; rep(i, k) { int tmp; cin >> tmp; --tmp; if (tmp == -1) f = true; exist[tmp] = true; } int id = 0; memset(Id, -1, sizeof(Id)); bool consecutive = false; for (int i = 0; i < n; ++i) { if (exist[i]) { if (!consecutive) id++, consecutive = true; len[id]++, Id[i] = id; } else consecutive = false; } int ma = 0; rep(i, n) if (Id[i] != -1) ma = max(ma, len[Id[i]]); if (f) { rep(i, n) { int l = 0, r = 0; if (i - 1 >= 0 && Id[i - 1] != -1) l = len[Id[i - 1]]; if (i + 1 < n && Id[i + 1] != -1) r = len[Id[i + 1]]; if (i - 1 >= 0 && i + 1 < n && Id[i - 1] == Id[i + 1]) ma = max(ma, l + 1); ma = max(ma, l + r + 1); } } if (ma == n + 1) ma--; cout << ma << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, x) for (int i = 0; i < x; ++i) #define all(a) begin(a), end(a) bool exist[100010]; int len[100010]; int Id[100010]; signed main() { int n, k; while (cin >> n >> k, n) { memset(exist, false, sizeof(exist)); memset(len, 0, sizeof(len)); memset(Id, 0, sizeof(Id)); bool f = false; rep(i, k) { int tmp; cin >> tmp; --tmp; if (tmp == -1) f = true; exist[tmp] = true; } int id = 0; memset(Id, -1, sizeof(Id)); bool consecutive = false; for (int i = 0; i < n; ++i) { if (exist[i]) { if (!consecutive) id++, consecutive = true; len[id]++, Id[i] = id; } else consecutive = false; } int ma = 0; rep(i, n) if (Id[i] != -1) ma = max(ma, len[Id[i]]); if (f) { rep(i, n) { int l = 0, r = 0; if (i - 1 >= 0 && Id[i - 1] != -1) l = len[Id[i - 1]]; if (i + 1 < n && Id[i + 1] != -1) r = len[Id[i + 1]]; if (i - 1 >= 0 && i + 1 < n && Id[i - 1] == Id[i + 1]) ma = max(ma, l + 1); else ma = max(ma, l + r + 1); } } if (ma == n + 1) ma--; cout << ma << endl; } }
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
1
400
#include <iostream> #include <string> using namespace std; int main() { int a; int b; int c; int h; int n; while (cin >> a >> b >> c) { if (a == 0 && b == 0 && c == 0) { break; } cin >> n; int d[n]; int e[n]; int f[n]; int g[n]; int i[a + b + c]; h = 0; while (h < n) { cin >> d[h]; cin >> e[h]; cin >> f[h]; cin >> g[h]; h = h + 1; } h = 0; while (h < a + b + c) { i[h] = 2; h = h + 1; } h = 0; while (h < n) { if (g[h] == 1) { i[d[h] - 1] = 1; i[e[h] - 1] = 1; i[f[h] - 1] = 1; } h = h + 1; } h = 0; while (h < n) { if (i[d[h] - 1] == 1 && i[e[h] - 1] == 1 && g[h] == 0) { i[f[h] - 1] == 0; } if (i[f[h] - 1] == 1 && i[e[h] - 1] == 1 && g[h] == 0) { i[d[h] - 1] == 0; } if (i[d[h] - 1] == 1 && i[f[h] - 1] == 1 && g[h] == 0) { i[e[h] - 1] == 0; } h = h + 1; } h = 0; while (h < a + b + c) { cout << i[h] << endl; h = h + 1; } } }
#include <iostream> #include <string> using namespace std; int main() { int a; int b; int c; int h; int n; while (cin >> a >> b >> c) { if (a == 0 && b == 0 && c == 0) { break; } cin >> n; int d[n]; int e[n]; int f[n]; int g[n]; int i[a + b + c]; h = 0; while (h < n) { cin >> d[h]; cin >> e[h]; cin >> f[h]; cin >> g[h]; h = h + 1; } h = 0; while (h < a + b + c) { i[h] = 2; h = h + 1; } h = 0; while (h < n) { if (g[h] == 1) { i[d[h] - 1] = 1; i[e[h] - 1] = 1; i[f[h] - 1] = 1; } h = h + 1; } h = 0; while (h < n) { if (i[d[h] - 1] == 1 && i[e[h] - 1] == 1 && g[h] == 0) { i[f[h] - 1] = 0; } if (i[f[h] - 1] == 1 && i[e[h] - 1] == 1 && g[h] == 0) { i[d[h] - 1] = 0; } if (i[d[h] - 1] == 1 && i[f[h] - 1] == 1 && g[h] == 0) { i[e[h] - 1] = 0; } h = h + 1; } h = 0; while (h < a + b + c) { cout << i[h] << endl; h = h + 1; } } }
[["-", 0, 57, 64, 9, 0, 1, 0, 16, 17, 60], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32]]
1
427
#include <algorithm> #include <cstdlib> #include <fstream> #include <iostream> #include <iterator> #include <map> #include <queue> #include <stack> #include <string> #include <vector> typedef long long int lli; using namespace std; int main() { int a, b, c, n; while (cin >> a >> b >> c && a != 0 && b != 0 && c != 0) { cin >> n; vector<int> parts(a + b + c + 1); vector<int> i(n), j(n), k(n), r(n); for (int l = 1; l <= a + b + c; ++l) { parts[l] = 2; } for (int l = 0; l < n; ++l) { cin >> i[l] >> j[l] >> k[l] >> r[l]; if (r[l] == 1) { parts[i[l]] = 1; parts[j[l]] = 1; parts[k[l]] = 1; } } for (int l = 0; l < n; ++l) { if (r[l] == 0) { if (parts[i[l]] == 1 && parts[j[l]] == 1 && parts[k[l]] == 2) parts[k[l]] = 0; else if (parts[i[l]] == 1 && parts[k[l]] == 1 && parts[j[l]] == 2) parts[j[l]] = 0; else if (parts[j[l]] == 1 && parts[k[l]] == 1 && parts[i[l]] == 2) parts[k[l]] = 0; } } for (int l = 1; l <= a + b + c; ++l) { cout << parts[l] << "\n"; } } return 0; }
#include <algorithm> #include <cstdlib> #include <fstream> #include <iostream> #include <iterator> #include <map> #include <queue> #include <stack> #include <string> #include <vector> typedef long long int lli; using namespace std; int main() { int a, b, c, n; while (cin >> a >> b >> c && a != 0 && b != 0 && c != 0) { cin >> n; vector<int> parts(a + b + c + 1); vector<int> i(n), j(n), k(n), r(n); for (int l = 1; l <= a + b + c; ++l) { parts[l] = 2; } for (int l = 0; l < n; ++l) { cin >> i[l] >> j[l] >> k[l] >> r[l]; if (r[l] == 1) { parts[i[l]] = 1; parts[j[l]] = 1; parts[k[l]] = 1; } } for (int l = 0; l < n; ++l) { if (r[l] == 0) { if (parts[i[l]] == 1 && parts[j[l]] == 1 && parts[k[l]] == 2) parts[k[l]] = 0; else if (parts[i[l]] == 1 && parts[k[l]] == 1 && parts[j[l]] == 2) parts[j[l]] = 0; else if (parts[j[l]] == 1 && parts[k[l]] == 1 && parts[i[l]] == 2) parts[i[l]] = 0; } } for (int l = 1; l <= a + b + c; ++l) { cout << parts[l] << "\n"; } } return 0; }
[["-", 0, 11, 31, 69, 341, 342, 0, 69, 28, 22], ["+", 0, 11, 31, 69, 341, 342, 0, 69, 28, 22]]
1
407
#include <algorithm> #include <iostream> using namespace std; int main() { int a, b, c, n, flag = 1; while (1) { cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) break; cin >> n; int p = 0, w[n], x[n], y[n], z[n], ans[a + b + c + 1]; for (int i = 0; i < a + b + c + 1; i++) ans[i] = 2; for (int i = 0; i < n; i++) { cin >> w[i] >> x[i] >> y[i] >> z[i]; if (z[i] == 1) { ans[w[i]] == 1; ans[x[i]] == 1; ans[y[i]] == 1; } } for (int i = 0; i < n; i++) { if (z[i] == 0) { if (ans[w[i]] == 1 && ans[x[i]] == 1 && ans[y[i]] == 2) ans[y[i]] = 0; if (ans[w[i]] == 1 && ans[x[i]] == 2 && ans[y[i]] == 1) ans[x[i]] = 0; if (ans[w[i]] == 2 && ans[x[i]] == 1 && ans[y[i]] == 1) ans[w[i]] = 0; } } for (int i = 1; i <= a + b + c; i++) cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int a, b, c, n, flag = 1; while (1) { cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) break; cin >> n; int p = 0, w[n], x[n], y[n], z[n], ans[a + b + c + 1]; for (int i = 0; i < a + b + c + 1; i++) ans[i] = 2; for (int i = 0; i < n; i++) { cin >> w[i] >> x[i] >> y[i] >> z[i]; if (z[i] == 1) { ans[w[i]] = 1; ans[x[i]] = 1; ans[y[i]] = 1; } } for (int i = 0; i < n; i++) { if (z[i] == 0) { if (ans[w[i]] == 1 && ans[x[i]] == 1 && ans[y[i]] == 2) ans[y[i]] = 0; if (ans[w[i]] == 1 && ans[x[i]] == 2 && ans[y[i]] == 1) ans[x[i]] = 0; if (ans[w[i]] == 2 && ans[x[i]] == 1 && ans[y[i]] == 1) ans[w[i]] = 0; } } for (int i = 1; i <= a + b + c; i++) cout << ans[i] << endl; } return 0; }
[["-", 0, 57, 64, 9, 0, 1, 0, 16, 17, 60], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32]]
1
386
for e in iter(input,'0 0 0'): d=[2]*-~sum(map(int,e.split())) f=[] for _ in[0]*int(input()): s,t,u,v=map(int,input().split()) if v:d[s]=d[t]=d[u]=1 else:f+=[(s,t,u)] for s,t,u in f: if d[t]*d[u]!=1:d[s]=0 if d[u]*d[s]!=1:d[t]=0 if d[s]*d[t]!=1:d[u]=0 print(d[1:],sep='\n')
for e in iter(input,'0 0 0'): d=[2]*-~sum(map(int,e.split())) f=[] for _ in[0]*int(input()): s,t,u,v=map(int,input().split()) if v:d[s]=d[t]=d[u]=1 else:f+=[(s,t,u)] for s,t,u in f: if d[t]*d[u]==1:d[s]=0 if d[u]*d[s]==1:d[t]=0 if d[s]*d[t]==1:d[u]=0 print(*d[1:],sep='\n')
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 60], ["+", 0, 652, 3, 4, 0, 206, 51, 661, 0, 48]]
5
183
#include <stdio.h> #include <string.h> int main() { // gp int a, b, n, x, y, i, j; // oHz int dp[17][17]; // while while (scanf("%d %d", &a, &b) != EOF && a && b) { // oH memset(dp, -1, sizeof(dp)); // ss_ scanf("%d", &n); // X^[guuoH0 for (i = 0; i <= a; i++) { dp[i][0] = 0; } for (i = 0; i <= b; i++) { dp[0][i] = 0; } dp[1][1] = 1; // X^[guoH1 for (i = 0; i < n; i++) { // ss_u scanf("%d %d", &x, &y); // ss_oH0 dp[x][y] = 0; } for (i = 1; i <= a; i++) { for (j = 1; j <= b; j++) { // oHvZs if (dp[i][j] != -1) { continue; } // n_oHuoHuoHv dp[i][j] = dp[i][j] + dp[i][j - 1]; } } // oHo printf("%d\n", dp[a][b]); } return 0; }
#include <stdio.h> #include <string.h> int main() { // gp int a, b, n, x, y, i, j; // oHz int dp[17][17]; // while while (scanf("%d %d", &a, &b) != EOF && a && b) { // oH memset(dp, -1, sizeof(dp)); // ss_ scanf("%d", &n); // X^[guuoH0 for (i = 0; i <= a; i++) { dp[i][0] = 0; } for (i = 0; i <= b; i++) { dp[0][i] = 0; } dp[1][1] = 1; // X^[guoH1 for (i = 0; i < n; i++) { // ss_u scanf("%d %d", &x, &y); // ss_oH0 dp[x][y] = 0; } for (i = 1; i <= a; i++) { for (j = 1; j <= b; j++) { // oHvZs if (dp[i][j] != -1) { continue; } // n_oHuoHuoHv dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } } // oHo printf("%d\n", dp[a][b]); } return 0; }
[["+", 12, 16, 31, 69, 28, 69, 71, 16, 17, 33], ["+", 12, 16, 31, 69, 28, 69, 71, 16, 12, 13]]
0
280
#include <stdio.h> int main(void) { int a, b, x, y, n, i, j; while (1) { int map[17][17] = {0}; int dp[17][17] = {0}; dp[1][1] = 1; scanf("%d %d", &a, &b); if (a == 0 && b == 0) break; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &x, &y); map[x][y] = -1; } for (i = 1; i <= b; i++) { for (j = 1; j <= a; j++) { if (map[j][i] == 0) dp[j][i] = dp[j - 1][i] + dp[j][i - 1]; } } printf("%d\n", dp[a][b]); } return 0; }
#include <stdio.h> int main(void) { int a, b, x, y, n, i, j; while (1) { int map[17][17] = {0}; int dp[17][17] = {0}; dp[1][1] = 1; scanf("%d %d", &a, &b); if (a == 0 && b == 0) break; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &x, &y); map[x][y] = -1; } for (i = 1; i <= b; i++) { for (j = 1; j <= a; j++) { if (map[j][i] == 0) dp[j][i] += dp[j - 1][i] + dp[j][i - 1]; } } printf("%d\n", dp[a][b]); } return 0; }
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 17, 107]]
0
228
#include <stdio.h> int main() { int board[17][17] = {0}; int i, j, n, x, y, p, q; while (scanf("%d%d", &x, &y), x + y) { scanf("%d", &n); for (i = 0; i < 17 * 17; i++) board[i % 17][i / 17] = 1; for (i = 0; i < n; i++) { scanf("%d%d", &p, &q); board[p][q] = 0; } /* for(i=1;i<=x;i++){ for(j=1;j<=y;j++){ printf("%d ",board[i][j]); }puts(""); } */ board[1][1] = 1; for (i = 1; i < 17; i++) { if (board[1][i] < 0) board[1][i] = board[1][i - 1]; if (board[i][1] < 0) board[i][1] = board[i - 1][1]; } for (i = 2; i <= x; i++) { for (j = 2; j <= y; j++) { if (board[i][j] < 0) { board[i][j] = board[i][j - 1] + board[i - 1][j]; } } } /* for(i=1;i<=x;i++){ for(j=1;j<=y;j++){ printf("%d ",board[i][j]); }puts(""); } */ printf("%d\n", board[x][y]); } return 0; }
#include <stdio.h> int main() { int board[17][17] = {0}; int i, j, n, x, y, p, q; while (scanf("%d%d", &x, &y), x + y) { scanf("%d", &n); for (i = 0; i < 17 * 17; i++) board[i % 17][i / 17] = -1; for (i = 0; i < n; i++) { scanf("%d%d", &p, &q); board[p][q] = 0; } /* for(i=1;i<=x;i++){ for(j=1;j<=y;j++){ printf("%d ",board[i][j]); }puts(""); } */ board[1][1] = 1; for (i = 1; i < 17; i++) { if (board[1][i] < 0) board[1][i] = board[1][i - 1]; if (board[i][1] < 0) board[i][1] = board[i - 1][1]; } for (i = 2; i <= x; i++) { for (j = 2; j <= y; j++) { if (board[i][j] < 0) { board[i][j] = board[i][j - 1] + board[i - 1][j]; } } } /* for(i=1;i<=x;i++){ for(j=1;j<=y;j++){ printf("%d ",board[i][j]); }puts(""); } */ printf("%d\n", board[x][y]); } return 0; }
[["-", 8, 9, 0, 7, 8, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 1, 0, 11, 12, 13]]
0
312
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int a, b; int n; int i, j; long long int **count; while (scanf("%d %d", &a, &b), a) { count = (long long int **)malloc(sizeof(long long int *) * a); for (i = 0; i < a; i++) { count[i] = (long long int *)malloc(sizeof(long long int) * b); for (j = 0; j < b; j++) { count[i][j] = 0; } } scanf("%d", &n); for (i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); count[x - 1][y - 1] = -1; } count[0][0] = 1; for (i = 1; i < b; i++) { if (count[0][i] != -1) count[0][i] = count[0][i - 1]; else count[0][i] = 0; } for (i = 1; i < a; i++) { if (count[i][0] != -1) count[i][0] = count[i - 1][0]; else count[i][0] = 0; for (j = 1; j < b; j++) { if (count[i][j] != -1) count[i][j] = count[i - 1][j] + count[i][j - 1]; else count[i][j] = 0; } } printf("%lld", count[a - 1][b - 1]); } return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int a, b; int n; int i, j; long long int **count; while (scanf("%d %d", &a, &b), a) { count = (long long int **)malloc(sizeof(long long int *) * a); for (i = 0; i < a; i++) { count[i] = (long long int *)malloc(sizeof(long long int) * b); for (j = 0; j < b; j++) { count[i][j] = 0; } } scanf("%d", &n); for (i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); count[x - 1][y - 1] = -1; } count[0][0] = 1; for (i = 1; i < b; i++) { if (count[0][i] != -1) count[0][i] = count[0][i - 1]; else count[0][i] = 0; } for (i = 1; i < a; i++) { if (count[i][0] != -1) count[i][0] = count[i - 1][0]; else count[i][0] = 0; for (j = 1; j < b; j++) { if (count[i][j] != -1) count[i][j] = count[i - 1][j] + count[i][j - 1]; else count[i][j] = 0; } } printf("%lld\n", count[a - 1][b - 1]); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
403
#include <bits/stdc++.h> using namespace std; int area[18][18]; int a, b, n; int ans = 0; int saiki(int x, int y) { // cout << x << ' ' << y << endl; if (area[x][y] == -1) return 0; if (x == a && y == b) { // cout << 'z' << endl; return 1; } ans += saiki(x, y + 1); ans += saiki(x + 1, y); return 0; } int main() { int x, y; memset(area, -1, sizeof(area)); while (1) { cin >> a >> b; if (a == 0 && b == 0) break; for (int i = 1; i <= a; i++) { for (int j = 1; j <= b; j++) { area[i][j] = 0; } } cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; area[x][y] = -1; } saiki(1, 1); cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int area[18][18]; int a, b, n; int ans = 0; int saiki(int x, int y) { // cout << x << ' ' << y << endl; if (area[x][y] == -1) return 0; if (x == a && y == b) { // cout << 'z' << endl; return 1; } ans += saiki(x, y + 1); ans += saiki(x + 1, y); return 0; } int main() { int x, y; memset(area, -1, sizeof(area)); while (1) { ans = 0; cin >> a >> b; if (a == 0 && b == 0) break; for (int i = 1; i <= a; i++) { for (int j = 1; j <= b; j++) { area[i][j] = 0; } } cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; area[x][y] = -1; } saiki(1, 1); cout << ans << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
233
#include <cstdio> #include <iostream> using namespace std; const int N = 40; int main() { while (1) { int a, b, n, x, y; long f[17][17]; scanf(" %d %d", &a, &b); if (a == 0 && b == 0) break; scanf(" %d", &n); //入力なしは-1 for (int i = 1; i <= a; ++i) for (int j = 1; j <= b; ++j) f[i][j] = -1; //通れないところは0 for (int i = 0; i < n; ++i) { scanf(" %d %d", &x, &y); f[x][y] = 0; } //端を1で初期化(通れないところを除く) bool flag = true; for (int i = 1; i <= a; ++i) { if (flag && f[i][1] == -1) f[i][1] = 1; else { flag = false; f[i][1] = 0; } } flag = true; for (int i = 1; i <= b; ++i) { if (flag && f[1][i] == -1) f[1][i] = 1; else { flag = false; f[1][i] = 0; } } //左と下から足していく for (int i = 2; i <= a; ++i) { for (int j = 2; j <= b; ++j) { if (f[i][j] == -1) { f[i][j] = f[i - 1][j] + f[i][j - 1]; } } } printf("%ld\n", f[a][b]); } return 0; }
#include <cstdio> #include <iostream> using namespace std; const int N = 40; int main() { while (1) { int a, b, n, x, y; long f[17][17]; scanf(" %d %d", &a, &b); if (a == 0 && b == 0) break; scanf(" %d", &n); //入力なしは-1 for (int i = 1; i <= a; ++i) for (int j = 1; j <= b; ++j) f[i][j] = -1; //通れないところは0 for (int i = 0; i < n; ++i) { scanf(" %d %d", &x, &y); f[x][y] = 0; } //端を1で初期化(通れないところを除く) bool flag = true; for (int i = 1; i <= a; ++i) { if (flag && f[i][1] == -1) f[i][1] = 1; else { flag = false; f[i][1] = 0; } } flag = true; for (int i = 2; i <= b; ++i) { if (flag && f[1][i] == -1) f[1][i] = 1; else { flag = false; f[1][i] = 0; } } //左と下から足していく for (int i = 2; i <= a; ++i) { for (int j = 2; j <= b; ++j) { if (f[i][j] == -1) { f[i][j] = f[i - 1][j] + f[i][j - 1]; } } } /* //confirm for(int i=b; i>=1; --i){ for(int j=1; j<=a; ++j){ printf("%3ld", f[j][i]); } printf("\n"); } */ printf("%ld\n", f[a][b]); } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
378
#include <algorithm> #include <cstdio> #include <math.h> #include <string.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) const int INF = 1001001001; int A, B; int N; long long int DP[20][20]; int main() { while (1) { memset(DP, 0, sizeof(DP)); scanf("%d %d", &A, &B); if (A == 0 && B == 0) break; scanf("%d", &N); rep(i, N) { int a, b; scanf("%d %d", &a, &b); DP[a - 1][b - 1] = -1; } rep(i, A) { rep(j, B) { if (DP[i][j] == -1) continue; if (i == 0 && j == 0) { DP[0][0] = 1; continue; } if (i == 0) { if (DP[i][j - 1] > 0) DP[i][j] = 1; continue; } else if (DP[i - 1][j] != -1) DP[i][j] += DP[i - 1][j]; if (j == 0) { if (DP[i - 1][j] > 0) DP[i][j] = 1; continue; } else if (DP[i][j - 1] != -1) DP[i][j] += DP[i][j - 1]; } } printf("%lld", DP[A - 1][B - 1]); } }
#include <algorithm> #include <cstdio> #include <math.h> #include <string.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) const int INF = 1001001001; int A, B; int N; long long int DP[20][20]; int main() { while (1) { memset(DP, 0, sizeof(DP)); scanf("%d %d", &A, &B); if (A == 0 && B == 0) break; scanf("%d", &N); rep(i, N) { int a, b; scanf("%d %d", &a, &b); DP[a - 1][b - 1] = -1; } rep(i, A) { rep(j, B) { if (DP[i][j] == -1) continue; if (i == 0 && j == 0) { DP[0][0] = 1; continue; } if (i == 0) { if (DP[i][j - 1] > 0) DP[i][j] = 1; continue; } else if (DP[i - 1][j] != -1) DP[i][j] += DP[i - 1][j]; if (j == 0) { if (DP[i - 1][j] > 0) DP[i][j] = 1; continue; } else if (DP[i][j - 1] != -1) DP[i][j] += DP[i][j - 1]; } } printf("%lld\n", DP[A - 1][B - 1]); } }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
351
#include <iostream> #include <vector> int main(void) { // make street int num_row, num_col; while (std::cin >> num_row >> num_col, num_row == 0 && num_col == 0) { // std::cin >> num_row >> num_col; std::vector<int> street(num_row * num_col, 1); // make stop int stop_num, row, col; std::cin >> stop_num; for (int i = 0; i < stop_num; ++i) { std::cin >> row >> col; street[num_row * (col - 1) + (row - 1)] = 0; } // calc int lRoad, uRoad; // left road, under road for (int j = 0; j < num_col; ++j) { for (int k = 0; k < num_row; ++k) { if (j + k != 0) { if (street[j * num_row + k] != 0) { lRoad = k == 0 ? 0 : street[j * num_row + k - 1]; uRoad = j == 0 ? 0 : street[(j - 1) * num_row + k]; street[j * num_row + k] = lRoad + uRoad; } } } } std::cout << street.back() << std::endl; } return 0; }
#include <iostream> #include <vector> int main(void) { int num_row, num_col; while (std::cin >> num_row >> num_col, num_row != 0 && num_col != 0) { // make street std::vector<int> street(num_row * num_col, 1); // make stop int stop_num, row, col; std::cin >> stop_num; for (int i = 0; i < stop_num; ++i) { std::cin >> row >> col; street[num_row * (col - 1) + (row - 1)] = 0; } // calc int lRoad, uRoad; // left road, under road for (int j = 0; j < num_col; ++j) { for (int k = 0; k < num_row; ++k) { if (j + k != 0) { if (street[j * num_row + k] != 0) { lRoad = k == 0 ? 0 : street[j * num_row + k - 1]; uRoad = j == 0 ? 0 : street[(j - 1) * num_row + k]; street[j * num_row + k] = lRoad + uRoad; } } } } std::cout << street.back() << std::endl; } return 0; }
[["-", 15, 339, 51, 34, 12, 16, 31, 16, 17, 60], ["+", 15, 339, 51, 34, 12, 16, 31, 16, 17, 79], ["-", 15, 339, 51, 34, 12, 16, 12, 16, 17, 60], ["+", 15, 339, 51, 34, 12, 16, 12, 16, 17, 79]]
1
244
#include <iostream> #include <vector> const int Max_a = 17; // 1 <= a <= 16 const int Max_b = 17; // 1 <= b <= 16 bool memo[Max_a][Max_b]; // memo for dp void format() { for (u_int i = 0; i < Max_a; ++i) { for (u_int j = 0; j < Max_b; ++j) { if (i == 0 || j == 0) { // not use memo[0][] and memo[][0] memo[i][j] = true; } else { memo[i][j] = false; } } } } int calcRoad(u_int x, u_int y) { // initialization if (x == 1 && y == 1) { return 1; } else if (x == 0 || y == 0) { return 0; } else { int num; if (memo[x - 1][y] && memo[x][y - 1]) { // if it was caliculated return 0; } else if (memo[x - 1][y]) { num = calcRoad(x, y - 1); return num; } else if (memo[x][y - 1]) { num = calcRoad(x - 1, y); return num; } else { num = calcRoad(x - 1, y); +calcRoad(x, y - 1); return num; } } } int main() { u_int a; // width u_int b; // height while (std::cin >> a >> b) { if (a == 0 && b == 0) { break; } // construction format(); u_int n; std::cin >> n; for (u_int i = 0; i < n; ++i) { u_int x, y; std::cin >> x >> y; memo[x][y] = true; } // solve by dp std::cout << calcRoad(a, b) << std::endl; } return 0; }
#include <iostream> #include <vector> const int Max_a = 17; // 1 <= a <= 16 const int Max_b = 17; // 1 <= b <= 16 bool memo[Max_a][Max_b]; // memo for dp void format() { for (u_int i = 0; i < Max_a; ++i) { for (u_int j = 0; j < Max_b; ++j) { if (i == 0 || j == 0) { // not use memo[0][] and memo[][0] memo[i][j] = true; } else { memo[i][j] = false; } } } } int calcRoad(u_int x, u_int y) { // initialization if (x == 1 && y == 1) { return 1; } else if (x == 0 || y == 0) { return 0; } else { int num; if (memo[x - 1][y] && memo[x][y - 1]) { // if it was caliculated return 0; } else if (memo[x - 1][y]) { num = calcRoad(x, y - 1); return num; } else if (memo[x][y - 1]) { num = calcRoad(x - 1, y); return num; } else { num = calcRoad(x - 1, y) + calcRoad(x, y - 1); return num; } } } int main() { u_int a; // width u_int b; // height while (std::cin >> a >> b) { if (a == 0 && b == 0) { break; } // construction format(); u_int n; std::cin >> n; for (u_int i = 0; i < n; ++i) { u_int x, y; std::cin >> x >> y; memo[x][y] = true; } // solve by dp std::cout << calcRoad(a, b) << std::endl; } return 0; }
[["-", 0, 57, 75, 76, 0, 9, 0, 1, 0, 35]]
1
376
#include <algorithm> #include <iostream> #include <vector> int main() { int a, b, x, y; while (std::cin >> a >> b) { if (a == 0 && b == 0) { break; } std::vector<std::vector<int>> road(a, std::vector<int>(b, 1)); int num = 0; std::cin >> num; for (int i = 0; i < num; ++i) { std::cin >> x >> y; road.at(x).at(y) = 0; } for (int i = 0; i < a; ++i) { for (int j = 0; j < b; ++j) { // start point & point under construction if (road.at(i).at(j) != 0 && (i + j) != 0) { if (i == 0) { if (road.at(i).at(j - 1) != 0) { road.at(i).at(j) = road.at(i).at(j - 1); } else { road.at(i).at(j) = 0; } } else if (j == 0) { if (road.at(i - 1).at(j) != 0) { road.at(i).at(j) = road.at(i - 1).at(j); } else { road.at(i).at(j) = 0; } } else { road.at(i).at(j) = road.at(i).at(j - 1) + road.at(i - 1).at(j); } } } } std::cout << road.at(a - 1).at(b - 1) << std::endl; } }
#include <algorithm> #include <iostream> #include <vector> int main() { int a, b, x, y; while (std::cin >> a >> b) { if (a == 0 && b == 0) { break; } std::vector<std::vector<int>> road(a, std::vector<int>(b, 1)); int num = 0; std::cin >> num; for (int i = 0; i < num; ++i) { std::cin >> x >> y; road.at(x - 1).at(y - 1) = 0; } for (int i = 0; i < a; ++i) { for (int j = 0; j < b; ++j) { // start point & point under construction if (road.at(i).at(j) != 0 && (i + j) != 0) { if (i == 0) { if (road.at(i).at(j - 1) != 0) { road.at(i).at(j) = road.at(i).at(j - 1); } else { road.at(i).at(j) = 0; } } else if (j == 0) { if (road.at(i - 1).at(j) != 0) { road.at(i).at(j) = road.at(i - 1).at(j); } else { road.at(i).at(j) = 0; } } else { road.at(i).at(j) = road.at(i).at(j - 1) + road.at(i - 1).at(j); } } } } std::cout << road.at(a - 1).at(b - 1) << std::endl; } }
[["+", 63, 118, 28, 2, 3, 4, 0, 16, 17, 33], ["+", 63, 118, 28, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 11, 31, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 11, 31, 2, 3, 4, 0, 16, 12, 13]]
1
393
#include <iostream> #include <stdlib.h> using namespace std; int main() { int a, b; while (cin >> a >> b, a | b) { int x, y, m = 0; int d[a * b] = {}; int k; cin >> k; for (int i = 0; i < k; ++i) { cin >> x >> y; x--; y--; d[x + y * a] = 1; } int dp[2][a * b]; for (int i = 0; i < 2; ++i) for (int j = 0; j < a * b; ++j) dp[i][j] = 0; dp[1 - m][0] = 1; while (true) { for (y = 0; y < b; ++y) { for (x = 0; x < a; ++x) { if (d[x + y * a]) continue; if (dp[m][x + y * a] == 0) { if (x >= 1) { dp[m][x + y * a] += dp[1 - m][(x - 1) + y * a]; } if (y >= 1) { dp[m][x + y * a] += dp[1 - m][x + (y - 1) * a]; } } } } bool t = false; for (int i = 0; i < a * b; ++i) { if (dp[1 - m][i] != dp[m][i]) t = true; dp[1 - m][i] = dp[m][i]; } if (!t) { cout << dp[m][a * b - 1] << endl; return 0; } m = 1 - m; } } }
#include <iostream> #include <stdlib.h> using namespace std; int main() { int a, b; while (cin >> a >> b, a | b) { int x, y, m = 0; int d[a * b] = {}; int k; cin >> k; for (int i = 0; i < k; ++i) { cin >> x >> y; x--; y--; d[x + y * a] = 1; } int dp[2][a * b]; for (int i = 0; i < 2; ++i) for (int j = 0; j < a * b; ++j) dp[i][j] = 0; dp[1 - m][0] = 1; while (true) { for (y = 0; y < b; ++y) { for (x = 0; x < a; ++x) { if (d[x + y * a]) continue; if (dp[m][x + y * a] == 0) { if (x >= 1) { dp[m][x + y * a] += dp[1 - m][(x - 1) + y * a]; } if (y >= 1) { dp[m][x + y * a] += dp[1 - m][x + (y - 1) * a]; } } } } bool t = false; for (int i = 0; i < a * b; ++i) { if (dp[1 - m][i] != dp[m][i]) t = true; dp[1 - m][i] = dp[m][i]; } if (!t) { cout << dp[m][a * b - 1] << endl; break; } m = 1 - m; } } }
[["-", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["-", 8, 9, 0, 57, 64, 9, 0, 37, 0, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94]]
1
402
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int zahyo[16][16]; int main() { int x, y, a, b, c; while (1) { memset(zahyo, -1, sizeof(int) * 16 * 16); for (int i = 0; i < 16; i++) { zahyo[i][0] = 1; zahyo[0][i] = 1; } scanf("%d%d", &x, &y); if (x == 0 && y == 0) return 0; scanf("%d", &c); for (int i = 0; i < c; i++) { scanf("%d%d", &a, &b); zahyo[a - 1][b - 1] = 0; if (b = 1) { for (int j = a - 1; j < 16; j++) zahyo[j][0] = 0; } if (a = 1) { for (int j = b - 1; j < 16; j++) zahyo[0][j] = 0; } } for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (zahyo[i][j] == -1) zahyo[i][j] = zahyo[i - 1][j] + zahyo[i][j - 1]; } } printf("%d\n", zahyo[x - 1][y - 1]); } }
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int zahyo[16][16]; int main() { int x, y, a, b, c; while (1) { memset(zahyo, -1, sizeof(int) * 16 * 16); for (int i = 0; i < 16; i++) { zahyo[i][0] = 1; zahyo[0][i] = 1; } scanf("%d%d", &x, &y); if (x == 0 && y == 0) return 0; scanf("%d", &c); for (int i = 0; i < c; i++) { scanf("%d%d", &a, &b); zahyo[a - 1][b - 1] = 0; if (b == 1) { for (int j = a - 1; j < 16; j++) zahyo[j][0] = 0; } if (a == 1) { for (int j = b - 1; j < 16; j++) zahyo[0][j] = 0; } } for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (zahyo[i][j] == -1) zahyo[i][j] = zahyo[i - 1][j] + zahyo[i][j - 1]; } } printf("%d\n", zahyo[x - 1][y - 1]); } }
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
333
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define reep(n1, n2, n3) for (int n1 = n3; n1 < n2; n1++) #define rep(n1, n2) reep(n1, n2, 0) #define pb push_back #define mp make_pair #define fr first #define sc second #define INF 1e9 using namespace std; typedef long long int lint; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vp; typedef pair<int, int> pi; typedef pair<int, pair<int, int>> pii; typedef vector<string> vs; const double PI = acos(-1.0); int dp[16][16]; bool field[16][16]; int main() { int w, h; while (cin >> w >> h, w) { int k; cin >> k; rep(i, k) { int a, b; cin >> a >> b; field[a - 1][b - 1] = true; } dp[0][0] = 1; rep(i, h) rep(j, w) { if (!field[i][j]) { if (i > 0) dp[i][j] += dp[i - 1][j]; if (j > 0) dp[i][j] += dp[i][j - 1]; } } cout << dp[h - 1][w - 1] << endl; rep(i, 16) rep(j, 16) { dp[i][j] = 0; field[i][j] = false; } } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define reep(n1, n2, n3) for (int n1 = n3; n1 < n2; n1++) #define rep(n1, n2) reep(n1, n2, 0) #define pb push_back #define mp make_pair #define fr first #define sc second #define INF 1e9 using namespace std; typedef long long int lint; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vp; typedef pair<int, int> pi; typedef pair<int, pair<int, int>> pii; typedef vector<string> vs; const double PI = acos(-1.0); int dp[16][16]; bool field[16][16]; int main() { int w, h; while (cin >> w >> h, w) { int k; cin >> k; rep(i, k) { int a, b; cin >> a >> b; field[b - 1][a - 1] = true; } dp[0][0] = 1; rep(i, h) rep(j, w) { if (!field[i][j]) { if (i > 0) dp[i][j] += dp[i - 1][j]; if (j > 0) dp[i][j] += dp[i][j - 1]; } } cout << dp[h - 1][w - 1] << endl; rep(i, 16) rep(j, 16) { dp[i][j] = 0; field[i][j] = false; } } }
[["-", 31, 69, 28, 69, 341, 342, 0, 16, 31, 22], ["+", 31, 69, 28, 69, 341, 342, 0, 16, 31, 22], ["-", 0, 11, 31, 69, 341, 342, 0, 16, 31, 22], ["+", 0, 11, 31, 69, 341, 342, 0, 16, 31, 22]]
1
359
while True: a, b = map(int, input().split()) if a == 0: break N = int(input()) memo = [[0 for i in range(a+1)] for j in range(b+1)] flag = [[False for i in range(a+1)] for j in range(b+1)] memo[1][1] = 1 flag[1][1] = True x = [0] * N y = [0] * N for i in range(N): x[i], y[i] = map(int, input().split()) flag[y[i]][x[i]] = True print(flag) for i in range(1, b+1): for j in range(1, a+1): if not flag[i][j]: flag[i][j] = True memo[i][j] = memo[i-1][j] + memo[i][j-1] print(memo[b][a])
while True: a, b = map(int, input().split()) if a == 0: break N = int(input()) memo = [[0 for i in range(a+1)] for j in range(b+1)] flag = [[False for i in range(a+1)] for j in range(b+1)] memo[1][1] = 1 flag[1][1] = True x = [0] * N y = [0] * N for i in range(N): x[i], y[i] = map(int, input().split()) flag[y[i]][x[i]] = True for i in range(1, b+1): for j in range(1, a+1): if not flag[i][j]: flag[i][j] = True memo[i][j] = memo[i-1][j] + memo[i][j-1] print(memo[b][a])
[["-", 0, 52, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
244
function maxSum(arr, len) { var sumArr = []; for (var i = 0; i < arr.length - len; i++) { var j = len; var sum = 0; if (i == 0) { while (j > 0) { sum += arr[i + j]; j--; } } else { sum = sumArr[i - 1] - arr[i - 1] + arr[i + j]; } sumArr.push(sum); } sumArr.sort(function(a, b) { return b - a; }); console.log(sumArr[0]); } var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var Arr = (input.trim()).split("\n"); var a; var b; for (var i = 0; i < Arr.length; i++) { var Line = Arr[i].split(" ").map(Number); if (Line.length == 2 || i == Arr.length - 1) { if (i != 0) maxSum(a, b); a = []; b = Line[1] - 0; } else { a.push(Line[0]); } if (Arr[i] == "0 0") break; }
function maxSum(arr, len) { var sumArr = []; for (var i = 0; i < arr.length - len; i++) { var j = len; var sum = 0; if (i == 0) { while (j >= 0) { sum += arr[i + j]; j--; } } else { sum = sumArr[i - 1] - arr[i - 1] + arr[i + j]; } sumArr.push(sum); } sumArr.sort(function(a, b) { return b - a; }); console.log(sumArr[0]); } var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var Arr = (input.trim()).split("\n"); var a; var b; for (var i = 0; i < Arr.length; i++) { var Line = Arr[i].split(" ").map(Number); if (Line.length == 2 || i == Arr.length - 1) { if (i != 0) maxSum(a, b); a = []; b = (Line[1] - 0) - 1; } else { a.push(Line[0]); } if (Arr[i] == "0 0") break; }
[["-", 64, 556, 0, 52, 15, 23, 0, 16, 17, 47], ["+", 64, 556, 0, 52, 15, 23, 0, 16, 17, 20], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 64, 556, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 556, 0, 1, 0, 11, 12, 16, 12, 555]]
2
289
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { // TODO ????????????????????????????????????????????? try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { String line; int k = 0, length = 0, i = 0, max = 0, sum = 0; boolean first = true; int[] card = null; while ((line = br.readLine()) != null) { if (line.equals("0 0")) break; if (first) { String[] tokens = line.split(" "); length = Integer.parseInt(tokens[0]); card = new int[length]; k = Integer.parseInt(tokens[1]); first = false; } else { card[i] = Integer.parseInt(line); i++; sum = 0; if (i >= k) { for (int j = i - 3; j < i; j++) { sum += card[j]; } if (i == k) { max = sum; } else if (sum > max) { max = sum; } } if (i == length) { System.out.println(max); first = true; } } } } } }
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { // TODO ????????????????????????????????????????????? try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { String line; int k = 0, length = 0, i = 0, max = 0, sum = 0; boolean first = true; int[] card = null; while ((line = br.readLine()) != null) { if (line.equals("0 0")) break; if (first) { String[] tokens = line.split(" "); length = Integer.parseInt(tokens[0]); card = new int[length]; k = Integer.parseInt(tokens[1]); first = false; i = 0; } else { card[i] = Integer.parseInt(line); i++; sum = 0; if (i >= k) { for (int j = i - k; j < i; j++) { sum += card[j]; } if (i == k) { max = sum; } else if (sum > max) { max = sum; } } if (i == length) { System.out.println(max); first = true; } } } } } }
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 499], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 502, 503, 49, 200, 51, 16, 12, 499], ["+", 0, 7, 502, 503, 49, 200, 51, 16, 12, 22]]
3
275
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int n = stdIn.nextInt(); int k = stdIn.nextInt(); int[] ans = new int[1000]; int index = 0; while (n != 0 || k != 0) { int sum = 0; int[] num = new int[n]; for (int i = 0; i < k; i++) { num[i] = stdIn.nextInt(); sum += num[i]; } for (int i = k; i < n; i++) { num[i] = stdIn.nextInt(); } int max = sum; for (int i = 0; i < n - k; i++) { int temp = sum - num[i] + num[i + k]; if (temp > max) { max = temp; } } ans[index] = max; index++; n = stdIn.nextInt(); k = stdIn.nextInt(); } for (int i = 0; i < index; i++) { System.out.println(ans[i]); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int n = stdIn.nextInt(); int k = stdIn.nextInt(); int[] ans = new int[10]; int index = 0; while (n != 0 || k != 0) { int sum = 0; int[] num = new int[n]; for (int i = 0; i < k; i++) { num[i] = stdIn.nextInt(); sum += num[i]; } for (int i = k; i < n; i++) { num[i] = stdIn.nextInt(); } int max = sum; for (int i = 0; i < n - k; i++) { sum = sum - num[i] + num[i + k]; if (sum > max) { max = sum; } } ans[index] = max; index++; n = stdIn.nextInt(); k = stdIn.nextInt(); } for (int i = 0; i < index; i++) { System.out.println(ans[i]); } } }
[["-", 0, 503, 49, 200, 51, 227, 497, 505, 0, 499], ["+", 0, 503, 49, 200, 51, 227, 497, 505, 0, 499], ["-", 0, 7, 8, 196, 0, 503, 39, 506, 0, 507], ["-", 0, 7, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 57, 15, 15, 0, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
3
264
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); int k = sc.nextInt(); if (n == 0 && k == 0) break; int[] a = new int[n]; int sum = 0, maxsum = 0; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); for (int i = 0; i < n - k; i++) { sum = 0; for (int j = 0; j < k; j++) { sum += a[i + j]; } if (sum > maxsum) maxsum = sum; } System.out.println(sum); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); int k = sc.nextInt(); if (n == 0 && k == 0) break; int[] a = new int[n]; int sum = 0, maxsum = 0; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); for (int i = 0; i < n - k; i++) { sum = 0; for (int j = 0; j < k; j++) { sum += a[i + j]; } if (sum > maxsum) maxsum = sum; } System.out.println(maxsum); } } }
[["-", 8, 196, 0, 1, 0, 492, 3, 4, 0, 22], ["+", 8, 196, 0, 1, 0, 492, 3, 4, 0, 22]]
3
182
#include <algorithm> #include <iostream> #include <queue> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define MP make_pair using namespace std; typedef vector<int> vi; typedef pair<int, int> P; int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); } int lcm(int n, int m) { int g = gcd(n, m); return n / g * m; } int main() { int n; while (cin >> n, n) { vector<vi> v(n + 1); vector<P> k(n + 1); vi w(n + 1), cnt(n + 1); w[0] = cnt[0] = 1; vi red(n + 1), blue(n + 1); rep(i, n) { int p, q, r, s; cin >> p >> q >> r >> s; int g = gcd(p, q); k[i + 1] = MP(p / g, q / g); red[i + 1] = r; blue[i + 1] = s; v[r].push_back(i + 1); v[s].push_back(i + 1); cnt[i + 1] += !!r + !!s; } queue<int> q; for (int i = 1; i <= n; i++) if (!cnt[i]) q.push(i); int last = -1; while (!q.empty()) { int m = q.front(); q.pop(); last = m; int l = lcm(k[m].first * w[blue[m]], k[m].second * w[red[m]]); w[m] = l / k[m].first + l / k[m].second; rep(i, v[m].size()) { cnt[v[m][i]]--; if (!cnt[v[m][i]]) q.push(v[m][i]); } } cout << w[last] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define MP make_pair using namespace std; typedef vector<int> vi; typedef pair<int, int> P; int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); } int lcm(int n, int m) { int g = gcd(n, m); return n / g * m; } int main() { int n; while (cin >> n, n) { vector<vi> v(n + 1); vector<P> k(n + 1); vi w(n + 1), cnt(n + 1); w[0] = cnt[0] = 1; vi red(n + 1), blue(n + 1); rep(i, n) { int p, q, r, s; cin >> p >> q >> r >> s; int g = gcd(p, q); k[i + 1] = MP(p / g, q / g); red[i + 1] = r; blue[i + 1] = s; v[r].push_back(i + 1); v[s].push_back(i + 1); cnt[i + 1] += !!r + !!s; } queue<int> q; for (int i = 1; i <= n; i++) if (!cnt[i]) q.push(i); int last = -1; while (!q.empty()) { int m = q.front(); q.pop(); last = m; int l = lcm(k[m].first * w[red[m]], k[m].second * w[blue[m]]); w[m] = l / k[m].first + l / k[m].second; rep(i, v[m].size()) { cnt[v[m][i]]--; if (!cnt[v[m][i]]) q.push(v[m][i]); } } cout << w[last] << endl; } return 0; }
[["-", 0, 16, 12, 69, 341, 342, 0, 69, 28, 22], ["+", 0, 16, 12, 69, 341, 342, 0, 69, 28, 22]]
1
485
require 'rational' class AOJ0520 def initialize(n) @n = n @poles = [] end def solve @n.times{ @poles << gets.split.map(&:to_i) } top = ((1..@n).to_a - @poles.map{ |p| [p[2], p[3]] }.flatten)[0] weight(top-1) end def weight(id) r = (@poles[id][2] == 0 ? 1 : weight(@poles[id][2]-1)) l = (@poles[id][3] == 0 ? 1 : weight(@poles[id][3]-1)) p = @poles[id][0] q = @poles[id][1] a = (r*q).lcm(l*p) / q b = (r*q).lcm(l*p) / p a+b end end while (n = gets.chomp.to_i) != 0 puts AOJ0520.new(n).solve end
require 'rational' class AOJ0520 def initialize(n) @n = n @poles = [] end def solve @n.times{ @poles << gets.split.map(&:to_i) } top = ((1..@n).to_a - @poles.map{ |p| [p[2], p[3]] }.flatten)[0] weight(top-1) end def weight(id) r = (@poles[id][2] == 0 ? 1 : weight(@poles[id][2]-1)) l = (@poles[id][3] == 0 ? 1 : weight(@poles[id][3]-1)) p = @poles[id][0] q = @poles[id][1] a = (r*p).lcm(l*q) / q b = (r*p).lcm(l*q) / p a+b end end while (n = gets.chomp.to_i) != 0 puts AOJ0520.new(n).solve end
[["-", 12, 738, 31, 652, 486, 739, 0, 738, 12, 22], ["+", 12, 738, 31, 652, 486, 739, 0, 738, 12, 22], ["-", 12, 738, 31, 652, 3, 4, 0, 738, 12, 22], ["+", 12, 738, 31, 652, 3, 4, 0, 738, 12, 22]]
4
218
def gcd(a, b): r = a % b if r: return gcd(b, r) return b def lcm(a, b): if a < b: a, b = b, a return a * b // gcd(a, b) def min_weight(m): p, q, r, b = bars[m - 1] red = q * (min_weight(r) if r else 1) blue = p * (min_weight(b) if b else 1) equilibrium = lcm(red, blue) return equilibrium // p + equilibrium // q while True: n = int(input()) if not n: break bars = [tuple(map(int, input().split())) for _ in range(n)] root_bar = set(range(1, n + 1)) for _, _, r, b in bars: if r: root_bar.remove(r) if b: root_bar.remove(b) print(min_weight(root_bar.pop()))
def gcd(a, b): r = a % b if r: return gcd(b, r) return b def lcm(a, b): if a < b: a, b = b, a return a * b // gcd(a, b) def min_weight(m): p, q, r, b = bars[m - 1] red = p * (min_weight(r) if r else 1) blue = q * (min_weight(b) if b else 1) equilibrium = lcm(red, blue) return equilibrium // p + equilibrium // q while True: n = int(input()) if not n: break bars = [tuple(map(int, input().split())) for _ in range(n)] root_bar = set(range(1, n + 1)) for _, _, r, b in bars: if r: root_bar.remove(r) if b: root_bar.remove(b) print(min_weight(root_bar.pop()))
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 31, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 31, 22]]
5
215
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = ""; int[] charge = new int[1000]; for (int i = 1; i < charge.length; i++) { int k = 1000 - i; charge[i] += k / 500; k %= 500; charge[i] += k / 100; k %= 100; charge[i] += k / 50; k %= 50; charge[i] += k / 10; k %= 10; charge[i] += k / 5; k %= 5; charge[i] += k; } br.readLine(); while ((line = br.readLine()) != null && !line.isEmpty()) { int n = Integer.parseInt(line); if (n == 0) { break; } System.out.println(charge[n]); } } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = ""; int[] charge = new int[1000]; for (int i = 1; i < charge.length; i++) { int k = 1000 - i; charge[i] += k / 500; k %= 500; charge[i] += k / 100; k %= 100; charge[i] += k / 50; k %= 50; charge[i] += k / 10; k %= 10; charge[i] += k / 5; k %= 5; charge[i] += k; } while ((line = br.readLine()) != null && !line.isEmpty()) { int n = Integer.parseInt(line); if (n == 0) { break; } System.out.println(charge[n]); } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 492, 500, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 492, 0, 131], ["-", 0, 195, 8, 196, 0, 1, 0, 492, 141, 22], ["-", 8, 196, 0, 1, 0, 492, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 492, 3, 4, 0, 25], ["-", 8, 498, 0, 195, 8, 196, 0, 1, 0, 35]]
3
230
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n; int sum; int m; while (true) { n = scan.nextInt(); m = 1000; sum = 0; if (n == 0) break; m -= n; sum += m / 500; m %= 500; sum += m / 100; m %= 100; sum += m / 50; m %= 50; sum += m / 10; m %= 10; sum += m / 5; m %= 5; sum += m; } System.out.println(sum); } }
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n; int sum; int m; while (true) { n = scan.nextInt(); m = 1000; sum = 0; if (n == 0) break; m -= n; sum += m / 500; m %= 500; sum += m / 100; m %= 100; sum += m / 50; m %= 50; sum += m / 10; m %= 10; sum += m / 5; m %= 5; sum += m; System.out.println(sum); } } }
[["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
3
140
#include <stdio.h> int main(void) { int paid; int change; int money; while (1) { scanf("%d", &paid); if (paid == 0) { break; } change = 1000 - paid; money = 0; if (change > 500) { money++; change -= 500; } if (change > 100) { money += change / 100; change -= (change / 100) * 100; } if (change > 50) { money += change / 50; change -= (change / 50) * 50; } if (change > 10) { money += change / 10; change -= (change / 10) * 10; } if (change > 5) { money += change / 5; change -= (change / 5) * 5; } if (change > 1) { money += change; } printf("%d\n", money); } return (0); }
#include <stdio.h> int main(void) { int paid; int change; int money; while (1) { scanf("%d", &paid); if (paid == 0) { break; } change = 1000 - paid; money = 0; if (change >= 500) { money++; change -= 500; } if (change >= 100) { money += change / 100; change -= (change / 100) * 100; } if (change >= 50) { money += change / 50; change -= (change / 50) * 50; } if (change >= 10) { money += change / 10; change -= (change / 10) * 10; } if (change >= 5) { money += change / 5; change -= (change / 5) * 5; } if (change >= 1) { money += change; } printf("%d\n", money); } return (0); }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 20]]
0
192
#include <stdio.h> int main(void) { int n, cha, count = 0; while (1) { scanf("%d", &n); if (n == 0) break; cha = 1000 - n; if (cha >= 500) { cha -= 500; count++; } while (cha >= 100) { cha -= 100; count++; } if (cha >= 50) { cha -= 50; count++; } while (cha >= 10) { cha -= 10; count++; } if (cha >= 5) { cha -= 5; count++; } while (cha >= 1) { cha -= 1; count++; } printf("%d\n", count); } return 0; }
#include <stdio.h> int main(void) { int n, cha, count = 0; while (1) { count = 0; scanf("%d", &n); if (n == 0) break; cha = 1000 - n; if (cha >= 500) { cha -= 500; count++; } while (cha >= 100) { cha -= 100; count++; } if (cha >= 50) { cha -= 50; count++; } while (cha >= 10) { cha -= 10; count++; } if (cha >= 5) { cha -= 5; count++; } while (cha >= 1) { cha -= 1; count++; } printf("%d\n", count); } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
0
151
#include <stdio.h> int main() { int coin, money = 1000, num; while (1) { scanf("%d", &num); if (num == 0) break; money -= num; coin = money / 500; money %= 500; coin += money / 100; money %= 100; coin += money / 50; money %= 50; coin += money / 10; money %= 10; coin += money / 5; money %= 5; coin += money; printf("%d\n", coin); } return 0; }
#include <stdio.h> int main() { int coin, money, num; while (1) { scanf("%d", &num); if (num == 0) break; money = 1000 - num; coin = money / 500; money %= 500; coin += money / 100; money %= 100; coin += money / 50; money %= 50; coin += money / 10; money %= 10; coin += money / 5; money %= 5; coin += money; printf("%d\n", coin); } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 110], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33]]
0
112
#include <stdio.h> int main() { int a, b, c, d, e, f, g, h, t; scanf("%d", &t); a = 1000 - t; b = a / 500; c = a % 500 / 100; d = a % 500 % 100 / 50; e = a % 500 % 100 % 50 / 10; f = a % 500 % 100 % 50 % 10 / 5; g = a % 500 % 100 % 50 % 10 % 5; h = b + c + d + e + f + g; if (t == 0) { return 0; } else { printf("%d\n", h); } return 0; }
#include <stdio.h> int main() { int a, b, c, d, e, f, g, h, t; while (1) { scanf("%d", &t); a = 1000 - t; b = a / 500; c = a % 500 / 100; d = a % 500 % 100 / 50; e = a % 500 % 100 % 50 / 10; f = a % 500 % 100 % 50 % 10 / 5; g = a % 500 % 100 % 50 % 10 % 5; h = b + c + d + e + f + g; if (t == 0) { return 0; } else { printf("%d\n", h); } } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 23, 0, 24], ["+", 0, 14, 8, 9, 0, 52, 15, 23, 0, 13], ["+", 0, 14, 8, 9, 0, 52, 15, 23, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
0
148
#include <stdio.h> int main() { int mon, a, b, c, d, e, f, y; while (1) { scanf("%d", &mon); y = 1000 - mon; if (mon <= 500) { a = (y - 500) / 100; b = (y - 500 - 100 * a) / 50; c = (y - 500 - 100 * a - 50 * b) / 10; d = (y - 500 - 100 * a - 50 * b - 10 * c) / 5; e = (y - 500 - 100 * a - 50 * b - 10 * c - 5 * d); f = 1 + a + b + c + d + e; printf("%d\n", f); } else if (mon >= 500) { a = y / 100; b = (y - 100 * a) / 50; c = (y - 100 * a - 50 * b) / 10; d = (y - 100 * a - 50 * b - 10 * c) / 5; e = (y - 100 * a - 50 * b - 10 * c - 5 * d); f = a + b + c + d + e; printf("%d\n", f); } if (mon == 0) { break; } } return 0; }
#include <stdio.h> int main() { int mon, a, b, c, d, e, f, y; while (1) { scanf("%d", &mon); y = 1000 - mon; if (mon <= 500 && mon > 0) { a = (y - 500) / 100; b = (y - 500 - 100 * a) / 50; c = (y - 500 - 100 * a - 50 * b) / 10; d = (y - 500 - 100 * a - 50 * b - 10 * c) / 5; e = (y - 500 - 100 * a - 50 * b - 10 * c - 5 * d); f = 1 + a + b + c + d + e; printf("%d\n", f); } else if (mon >= 500) { a = y / 100; b = (y - 100 * a) / 50; c = (y - 100 * a - 50 * b) / 10; d = (y - 100 * a - 50 * b - 10 * c) / 5; e = (y - 100 * a - 50 * b - 10 * c - 5 * d); f = a + b + c + d + e; printf("%d\n", f); } if (mon == 0) { break; } } return 0; }
[["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13]]
0
287
#include <stdio.h> const int money[] = {500, 100, 50, 10, 5, 1}; const int size = sizeof(money) / sizeof(int); int main(void) { int x, i, answer = 0; while (1) { scanf("%d", &x); if (x == 0) { break; } x = 1000 - x; for (i = 0; i < size; ++i) { answer += x / money[i]; x %= money[i]; } printf("%d\n", answer); } return 0; }
#include <stdio.h> const int money[] = {500, 100, 50, 10, 5, 1}; const int size = sizeof(money) / sizeof(int); int main(void) { int x, i, answer = 0; while (1) { scanf("%d", &x); if (x == 0) { break; } x = 1000 - x; answer = 0; for (i = 0; i < size; ++i) { answer += x / money[i]; x %= money[i]; } printf("%d\n", answer); } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
0
128
#include <stdio.h> int main() { int price, val = 0; while (1) { scanf("%d\n", &price); if (price == 0) break; price = 1000 - price; if (price / 500 == 1) { val++; price -= 500; } if (price / 100 > 0) { val = price / 100; price -= (price / 100) * 100; } if (price / 50 == 1) { val++; price -= 50; } if (price / 10 > 0) { val = price / 10; price -= (price / 10) * 10; } if (price / 5 == 1) { val++; price -= 5; } if (price / 1 > 0) { val = price / 1; price -= (price / 1); } printf("%d\n", val); val = 0; } return 0; }
#include <stdio.h> int main() { int price, val = 0; while (1) { scanf("%d\n", &price); if (price == 0) break; price = 1000 - price; if (price / 500 == 1) { val++; price -= 500; } if (price / 100 > 0) { val += price / 100; price -= (price / 100) * 100; } if (price / 50 == 1) { val++; price -= 50; } if (price / 10 > 0) { val += price / 10; price -= (price / 10) * 10; } if (price / 5 == 1) { val++; price -= 5; } if (price / 1 > 0) { val += price / 1; price -= (price / 1); } printf("%d\n", val); val = 0; } return 0; }
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107]]
0
190
#include <stdio.h> int main(void) { int n, i, cnt, x[] = {500, 100, 50, 10, 5, 1}; while (1) { scanf("%d", &n); if (n == 0) break; n = 1000 - n; cnt = 0; for (i = 0; i < 6; i++) { if (n > x[i]) { cnt += n / x[i]; n %= x[i]; } } printf("%d\n", cnt); } return 0; }
#include <stdio.h> int main(void) { int n, i, cnt, x[] = {500, 100, 50, 10, 5, 1}; while (1) { scanf("%d", &n); if (n == 0) break; n = 1000 - n; cnt = 0; for (i = 0; i < 6; i++) { if (n >= x[i]) { cnt += n / x[i]; n %= x[i]; } } printf("%d\n", cnt); } return 0; }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 20]]
0
123
b, s, k; main(c) { for (; scanf("%d", &c), c; s = !printf("%d\n", s)) { for (b = 1e3, c = b - c; b /= k++ % 2 ? 5 : 2; s += c / b, c %= b) ; } }
b, s, k; main(c) { for (; scanf("%d", &c), c; k = s = !printf("%d\n", s)) { for (b = 1e3, c = b - c; b /= k++ % 2 ? 5 : 2; s += c / b, c %= b) ; } }
[["+", 0, 14, 8, 9, 0, 7, 26, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 7, 26, 11, 17, 32]]
0
76
b, s, k; main(c) { for (; scanf("%d", &c), c; s = !printf("%d\n", s)) { for (b = 1e3, c = b - c; b /= k++ % 2 ? 5 : 2; s += c / b, c %= b) ; } }
b, s, k; main(c) { for (; scanf("%d", &c), c; s = !printf("%d\n", s)) { for (b = 1e3, c = b - c; b /= k % 2 ? 5 : 2; s += c / b, c %= b) k++; } }
[["-", 15, 11, 12, 41, 15, 16, 31, 27, 17, 29], ["+", 8, 9, 0, 7, 8, 1, 0, 27, 28, 22], ["+", 8, 9, 0, 7, 8, 1, 0, 27, 17, 29]]
0
76
#include <stdio.h> int main(void) { int a = 0, b = 0, c = 0, i, j; for (j = 0;; j++) { scanf("%d", &a); if (a == 0) { break; } b = 1000 - a; if (b >= 500) { b = b - 500; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 100) { break; } b = b - 100; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 50) { break; } b = b - 50; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 10) { break; } b = b - 10; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 5) { break; } b = b - 5; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 1) { break; } b = b - 1; c = c + 1; } printf("%d\n", c); } return 0; }
#include <stdio.h> int main(void) { int a = 0, b = 0, c = 0, i, j; for (j = 0;; j++) { scanf("%d", &a); if (a == 0) { break; } b = 1000 - a; if (b >= 500) { b = b - 500; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 100) { break; } b = b - 100; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 50) { break; } b = b - 50; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 10) { break; } b = b - 10; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 5) { break; } b = b - 5; c = c + 1; } for (i = 0;; i++) { if (0 <= b && b < 1) { break; } b = b - 1; c = c + 1; } printf("%d\n", c); c = 0; } return 0; }
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
0
287
#include <stdio.h> int main() { int a; int b, c; int k; scanf("%d", &a); while (a != 0) { if (a == 0) break; k = 0; a = 1000 - a; for (b = 0; a != 0; b++) { if (a >= 500) { k += 1; a = a - 500; } else if (a >= 100 && a < 500) { k += 1; a = a - 100; } else if (a >= 50 && a < 100) { k += 1; a = a - 50; } else if (a >= 10 && a < 50) { k += 1; a = a - 10; } else if (a >= 5 && a < 10) { k += 1; a = a - 5; } else if (a >= 1 && a < 5) { k += 1; a = a - 1; } } printf("%d", k); scanf("%d", &a); } return 0; }
#include <stdio.h> int main() { int a; int b, c; int k; scanf("%d", &a); while (a != 0) { if (a == 0) break; k = 0; a = 1000 - a; for (b = 0; a != 0; b++) { if (a >= 500) { k += 1; a = a - 500; } else if (a >= 100 && a < 500) { k += 1; a = a - 100; } else if (a >= 50 && a < 100) { k += 1; a = a - 50; } else if (a >= 10 && a < 50) { k += 1; a = a - 10; } else if (a >= 5 && a < 10) { k += 1; a = a - 5; } else if (a >= 1 && a < 5) { k += 1; a = a - 1; } } printf("%d\n", k); scanf("%d", &a); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
225
#include <algorithm> #include <iostream> using namespace std; int main() { int n, k; while (1) { cin >> k; if (k == 0) break; n = k / 500 + k % 500 / 100 + k % 500 % 100 / 50 + k % 500 % 100 % 50 / 10 + k % 500 % 100 % 50 % 10 / 5 + k % 500 % 100 % 50 % 10 % 5; cout << n << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int n, k; while (1) { cin >> k; if (k == 0) break; k = 1000 - k; n = k / 500 + k % 500 / 100 + k % 500 % 100 / 50 + k % 500 % 100 % 50 / 10 + k % 500 % 100 % 50 % 10 / 5 + k % 500 % 100 % 50 % 10 % 5; cout << n << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
100
#include <iostream> using namespace std; int main() { int C[6] = {500, 100, 50, 10, 5, 1}; // 0:500円 1:100円 2:50円 3:10円 4:5円 5:1円 int price; int change = 1000; int coin = 0; for (;;) { change = 1000; coin = 0; cin >> price; if (price == 0) break; change -= price; for (int i = 0; i < 6; i++) { coin += change / C[i]; change %= C[i]; } cout << coin; } return 0; }
#include <iostream> using namespace std; int main() { int C[6] = {500, 100, 50, 10, 5, 1}; // 0:500円 1:100円 2:50円 3:10円 4:5円 5:1円 int price; int change = 1000; int coin = 0; for (;;) { change = 1000; coin = 0; cin >> price; if (price == 0) break; change -= price; for (int i = 0; i < 6; i++) { coin += change / C[i]; change %= C[i]; } cout << coin << endl; } return 0; }
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
116
#include <algorithm> #include <bitset> #include <cstdio> #include <cstdlib> #include <iostream> #include <iterator> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <string> #include <time.h> #include <vector> using namespace std; #define FOR(I, F, N) for (int I = F; I < (int)(N); I++) #define rep(i, n) FOR(i, 0, n) #define FIN(V) cout << V << endl #define pb push_back #define INF (1 << 30) typedef pair<int, int> P; typedef long long ll; typedef priority_queue<int> pq; int StrToInt(string); string IntToStr(int); int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int C[6] = {500, 100, 50, 10, 5, 1}; int main(void) { int n; while (cin >> n, n) { cin >> n; n = 1000 - n; int cnt = 0; int val = 0; while (n != 0) { if (n - C[val] < 0) { val++; } else { n -= C[val]; cnt++; } } FIN(cnt); } return 0; } int StrToInt(string s) { stringstream ss; ss << s; int val; ss >> val; return val; } string IntToStr(int i) { stringstream ss; ss << i; return ss.str(); }
#include <algorithm> #include <bitset> #include <cstdio> #include <cstdlib> #include <iostream> #include <iterator> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <string> #include <time.h> #include <vector> using namespace std; #define FOR(I, F, N) for (int I = F; I < (int)(N); I++) #define rep(i, n) FOR(i, 0, n) #define FIN(V) cout << V << endl #define pb push_back #define INF (1 << 30) typedef pair<int, int> P; typedef long long ll; typedef priority_queue<int> pq; int StrToInt(string); string IntToStr(int); int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int C[6] = {500, 100, 50, 10, 5, 1}; int main(void) { int n; while (cin >> n, n) { n = 1000 - n; int cnt = 0; int val = 0; while (n != 0) { if (n - C[val] < 0) { val++; } else { n -= C[val]; cnt++; } } FIN(cnt); } return 0; } int StrToInt(string s) { stringstream ss; ss << s; int val; ss >> val; return val; } string IntToStr(int i) { stringstream ss; ss << i; return ss.str(); }
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 152], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
279
#include <stdio.h> int main(void) { int a, s, ss; while (1) { scanf("%d", &a); if (s == 0) break; s = 1000 - a; ss = s / 500; s = s % 500; ss += s / 100; s = s % 100; ss += s / 50; s = s % 50; ss += s / 10; s = s % 10; ss += s / 5; s = s % 5; ss += s / 1; printf("%d\n", ss); } return 0; }
#include <stdio.h> int main(void) { int a, s, ss; while (1) { scanf("%d", &a); if (a == 0) break; s = 1000 - a; ss = s / 500; s = s % 500; ss += s / 100; s = s % 100; ss += s / 50; s = s % 50; ss += s / 10; s = s % 10; ss += s / 5; s = s % 5; ss += s / 1; printf("%d\n", ss); } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
125
#include <algorithm> #include <bits/stdc++.h> #include <queue> #include <vector> using namespace std; typedef long long ll; int c[6] = {500, 100, 50, 10, 5, 1}; int main() { int n; while (scanf("%d", &n) && !n) { int m = 1000 - n; int res = 0; for (int i = 0; i < 6; i++) { res += m / c[i]; m %= c[i]; } printf("%d\n", res); } }
#include <algorithm> #include <bits/stdc++.h> #include <queue> #include <vector> using namespace std; typedef long long ll; int c[6] = {500, 100, 50, 10, 5, 1}; int main() { int n; while (scanf("%d", &n) && n) { int m = 1000 - n; int res = 0; for (int i = 0; i < 6; i++) { res += m / c[i]; m %= c[i]; } printf("%d\n", res); } }
[["-", 0, 52, 15, 339, 51, 16, 12, 91, 17, 111]]
1
117
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <string> using namespace std; int main() { int m, o, ans; while (1) { o = 0; ans = 0; cin >> m; if (m == 0) break; o = 1000 - m; if (o > 500) { o -= 500; ans++; } if (o / 100 > 0) { ans += o / 100; o %= 100; } if (o > 50) { o -= 50; ans++; } if (o / 10 > 0) { ans += o / 10; o %= 10; } if (o > 5) { ans++; o -= 5; } ans += o; cout << ans << endl; } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <string> using namespace std; int main() { int m, o, ans; while (1) { o = 0; ans = 0; cin >> m; if (m == 0) break; o = 1000 - m; if (o > 500) { o -= 500; ans++; } if (o / 100 > 0) { ans += o / 100; o %= 100; } if (o > 50) { o -= 50; ans++; } if (o / 10 > 0) { ans += o / 10; o %= 10; } if (o > 4) { ans++; o -= 5; } ans += o; cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
161
#include <iostream> using namespace std; int main() { while (true) { int a, b = 0; cin >> a; if (a == 0) break; a = 1000 - a; if (a > 500) { a = a - 500; b = b + 1; } b = b + a / 100; a = a % 100; if (a > 50) { a = a - 50; b = b + 1; } b = b + a / 10; a = a % 10; if (a > 5) { a = a - 5; b = b + 1; } b = b + a; cout << b << endl; } return 0; }
#include <iostream> using namespace std; int main() { while (true) { int a, b = 0; cin >> a; if (a == 0) break; a = 1000 - a; if (a >= 500) { a = a - 500; b = b + 1; } b = b + a / 100; a = a % 100; if (a >= 50) { a = a - 50; b = b + 1; } b = b + a / 10; a = a % 10; if (a >= 5) { a = a - 5; b = b + 1; } b = b + a; cout << b << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
146
#include <iostream> using namespace std; int main() { int a, b, c = 0; while (1) { cin >> a; if (a == 0) { break; } else { b = 1000 - a; c = b / 500; c = c + b % 500 / 100; c = c + b % 500 % 100 / 50; c = c + b % 500 % 100 % 50 / 10; c = c + b % 500 % 100 % 50 % 10 / 5; c = c + b % 500 % 100 % 50 % 10 & 5 / 1; a = 0; } cout << c << endl; } return 0; }
#include <iostream> using namespace std; int main() { int a, b, c = 0; while (1) { cin >> a; if (a == 0) { break; } else { b = 1000 - a; c = b / 500; c = c + b % 500 / 100; c = c + b % 500 % 100 / 50; c = c + b % 500 % 100 % 50 / 10; c = c + b % 500 % 100 % 50 % 10 / 5; c = c + b % 500 % 100 % 50 % 10 % 5 / 1; a = 0; } cout << c << endl; } return 0; }
[["-", 0, 9, 0, 1, 0, 11, 12, 16, 17, 67], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 17, 109]]
1
139
#include <algorithm> #include <cstdlib> #include <iostream> using namespace std; int main() { while (true) { int coin = 0; int price = 0; cin >> price; if (price == 0) { break; } for (auto temp : {500, 100, 50, 10, 5, 1}) { const auto temp_div = div(price, temp); coin += temp_div.quot; price = temp_div.rem; } cout << coin << endl; } return 0; }
#include <algorithm> #include <cstdlib> #include <iostream> using namespace std; int main() { while (true) { int coin = 0; int price = 0; cin >> price; if (price == 0) { break; } price = 1000 - price; for (auto temp : {500, 100, 50, 10, 5, 1}) { const auto temp_div = div(price, temp); coin += temp_div.quot; price = temp_div.rem; } cout << coin << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
99
#include <iostream> using namespace std; int main() { int coin[6] = {500, 100, 50, 10, 5, 1}; int cost; while (cin >> cost) { int count = 0; cost = 1000 - cost; for (int i = 0; i < 6; i++) { if (cost >= coin[i]) { count += cost / coin[i]; cost %= coin[i]; } } cout << count << endl; } return (0); }
#include <iostream> using namespace std; int main() { int coin[6] = {500, 100, 50, 10, 5, 1}; int cost; while (cin >> cost, cost) { int count = 0; cost = 1000 - cost; for (int i = 0; i < 6; i++) { if (cost >= coin[i]) { count += cost / coin[i]; cost %= coin[i]; } } cout << count << endl; } return (0); }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
1
108
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) int main() { const int coin[] = {500, 100, 50, 10, 5, 1}; int n; while (cin >> n) { int cnt = 0; for (int i = 0; i < 6; i++) { while (n + coin[i] <= 1000) { n += coin[i]; cnt++; } } cout << cnt << endl; } }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) int main() { const int coin[] = {500, 100, 50, 10, 5, 1}; int n; while (cin >> n, n) { int cnt = 0; for (int i = 0; i < 6; i++) { while (n + coin[i] <= 1000) { n += coin[i]; cnt++; } } cout << cnt << endl; } }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
1
101
#include <iostream> using namespace std; int main() { int value, coins = 0; while (true) { cin >> value; if (value == 0) break; value = 1000 - value; coins += value / 500; value %= 500; coins += value / 100; value %= 100; coins += value / 50; value %= 50; coins += value / 10; value %= 10; coins += value / 5; value %= 5; coins += value; cout << coins << endl; } return 0; }
#include <iostream> using namespace std; int main() { int value, coins = 0; while (true) { cin >> value; if (value == 0) break; value = 1000 - value; coins += value / 500; value %= 500; coins += value / 100; value %= 100; coins += value / 50; value %= 50; coins += value / 10; value %= 10; coins += value / 5; value %= 5; coins += value; cout << coins << endl; coins = 0; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
106
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; //// < "D:\D_Download\Visual Studio ///2015\Projects\programing_contest_c++\Debug\a.txt" int main() { while (1) { int N; cin >> N; if (!N) break; N = 1000 - N; int ans = 0; set<int> s; s = {500, 100, 50, 10, 5, 1}; for (auto m : s) { ans += N / m; N /= m; } cout << ans << endl; } return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; //// < "D:\D_Download\Visual Studio ///2015\Projects\programing_contest_c++\Debug\a.txt" int main() { while (1) { int N; cin >> N; if (!N) break; N = 1000 - N; int ans = 0; vector<int> s; s = {500, 100, 50, 10, 5, 1}; for (auto m : s) { ans += N / m; N %= m; } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 39, 344, 141, 78], ["+", 0, 52, 8, 9, 0, 43, 39, 344, 141, 78], ["-", 0, 338, 8, 9, 0, 1, 0, 11, 17, 90], ["+", 0, 338, 8, 9, 0, 1, 0, 11, 17, 132]]
1
131
#include <iostream> using namespace std; int main() { int money, count = 0, oturi[1000] = {}; int money2[6] = {500, 100, 50, 10, 5, 1}; for (int i = 0; i >= 0; i++) { cin >> money; count++; if (money == 0) break; oturi[i] = 1000 - money; } for (int j = 0; j < count; j++) { int maisu = 0; for (int i = 0; i < 6; i++) { maisu += oturi[j] / money2[i]; oturi[j] %= money2[i]; } cout << maisu << endl; } return 0; }
#include <iostream> using namespace std; int main() { int money, count = 0, oturi[1000] = {}; int money2[6] = {500, 100, 50, 10, 5, 1}; for (int i = 0; i >= 0; i++) { cin >> money; count++; if (money == 0) break; oturi[i] = 1000 - money; } for (int j = 0; j < count; j++) { int maisu = 0; for (int i = 0; i < 6; i++) { maisu += oturi[j] / money2[i]; oturi[j] %= money2[i]; } if (maisu > 0) cout << maisu << endl; } return 0; }
[["+", 8, 9, 0, 7, 8, 9, 0, 57, 0, 121], ["+", 0, 7, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 57, 15, 339, 0, 25]]
1
155
#include <iostream> using namespace std; int main() { int a, b = 0; while (1) { cin >> a; if (a == 0) break; a = 1000 - a; if (a > 500) { a -= 500; b++; } while (1) { if (a < 100) break; a -= 100; b++; } if (a > 50) { a -= 50; b++; } while (1) { if (a < 10) break; a -= 10; b++; } if (a > 5) { a -= 5; b++; } while (1) { if (a == 0) break; a -= 1; b++; } cout << b << endl; b = 0; } return 0; }
#include <iostream> using namespace std; int main() { int a, b = 0; while (1) { cin >> a; if (a == 0) break; a = 1000 - a; if (a >= 500) { a -= 500; b++; } while (1) { if (a < 100) break; a -= 100; b++; } if (a >= 50) { a -= 50; b++; } while (1) { if (a < 10) break; a -= 10; b++; } if (a >= 5) { a -= 5; b++; } while (1) { if (a == 0) break; a -= 1; b++; } cout << b << endl; b = 0; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
164
#include <iostream> using namespace std; int main() { int yen; int ans = 0; while (cin >> yen) { if (yen == 0) break; ans = yen % 5; yen /= 5; ans += yen % 2; yen /= 2; ans += yen % 5; yen /= 5; ans += yen % 2; yen /= 2; ans += yen % 5; ans += yen / 5; cout << ans << endl; } }
#include <iostream> using namespace std; int main() { int yen; int ans = 0; while (cin >> yen) { if (yen == 0) break; yen = 1000 - yen; ans = yen % 5; yen /= 5; ans += yen % 2; yen /= 2; ans += yen % 5; yen /= 5; ans += yen % 2; yen /= 2; ans += yen % 5; ans += yen / 5; cout << ans << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
94
#include <iostream> using namespace std; int main(void) { // Here your code ! int n = 1; int pay; while (n) { int cent = 0; cin >> n; if (n == 0) { break; } pay = 1000 - n; if (pay >= 500) { pay -= 500; cent++; } while (pay >= 100) { pay -= 100; cent++; } while (pay >= 50) { pay -= 50; cent++; } while (pay >= 10) { pay -= 10; cent++; } while (pay >= 5) { pay -= 5; cent++; } while (pay >= 1) { pay -= 1; cent++; } cout << cent << "endl"; } return 0; }
#include <iostream> using namespace std; int main(void) { // Here your code ! int n = 1; int pay; while (n) { int cent = 0; cin >> n; if (n == 0) { break; } pay = 1000 - n; if (pay >= 500) { pay -= 500; cent++; } while (pay >= 100) { pay -= 100; cent++; } while (pay >= 50) { pay -= 50; cent++; } while (pay >= 10) { pay -= 10; cent++; } while (pay >= 5) { pay -= 5; cent++; } while (pay >= 1) { pay -= 1; cent++; } cout << cent << "\n"; } return 0; }
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 44]]
1
154
#include <stdio.h> int N; int coin[6] = {500, 100, 50, 10, 5, 1}; int ans = 0; int main(void) { while (true) { scanf("%d", &N); if (N == 0) { break; } int res = 1000 - N; while (res != 0) { if (res >= 500) { ans += res / 500; res -= 500 * (res / 500); } else if (res >= 100) { ans += res / 100; res -= 100 * (res / 100); } else if (res >= 50) { ans += res / 50; res -= 50 * (res / 50); } else if (res >= 10) { ans += res / 10; res -= 10 * (res / 10); } else if (res >= 5) { ans += res / 5; res -= 5 * (res / 5); } else { ans += res; res = 0; } } printf("%d\n", ans); } return 0; }
#include <stdio.h> int N; int coin[6] = {500, 100, 50, 10, 5, 1}; int ans = 0; int main(void) { while (true) { scanf("%d", &N); if (N == 0) { break; } ans = 0; int res = 1000 - N; while (res != 0) { if (res >= 500) { ans += res / 500; res -= 500 * (res / 500); } else if (res >= 100) { ans += res / 100; res -= 100 * (res / 100); } else if (res >= 50) { ans += res / 50; res -= 50 * (res / 50); } else if (res >= 10) { ans += res / 10; res -= 10 * (res / 10); } else if (res >= 5) { ans += res / 5; res -= 5 * (res / 5); } else { ans += res; res = 0; } } printf("%d\n", ans); } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
226
#include <iostream> using namespace std; int main() { int cut = 0; int a; int b; while (1) { cin >> a; if (a == 0) break; b = 1000 - a; cut += b / 500; b = b % 500; cut += b / 100; b = b % 100; cut += b / 50; b = b % 50; cut += b / 10; b = b % 10; cut += b / 5; b = b % 5; cut += b; cout << cut << endl; } return 0; }
#include <iostream> using namespace std; int main() { int cut = 0; int a; int b; while (1) { cin >> a; cut = 0; if (a == 0) { break; } b = 1000 - a; cut += b / 500; b = b % 500; cut += b / 100; b = b % 100; cut += b / 50; b = b % 50; cut += b / 10; b = b % 10; cut += b / 5; b = b % 5; cut += b; cout << cut << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
1
120
#include <algorithm> #include <chrono> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; int main() { int n; while (cin >> n) { n = 1000 - n; int sum = 0; int c[6] = {500, 100, 50, 10, 5, 1}; for (int i = 0; i < 6; i++) { while (n >= c[i]) { n -= c[i]; sum++; } } cout << sum << endl; } }
#include <algorithm> #include <chrono> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; int main() { int n; while (cin >> n && n != 0) { n = 1000 - n; int sum = 0; int c[6] = {500, 100, 50, 10, 5, 1}; for (int i = 0; i < 6; i++) { while (n >= c[i]) { n -= c[i]; sum++; } } cout << sum << endl; } }
[["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 17, 79], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 12, 13]]
1
128
#include <algorithm> #include <array> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define vi vector<int> #define vvi vector<vector<int>> #define ll long long int #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vc vector<char> #define vs vector<string> #define ld long double #define INF 1e9 #define EPS 0.0000000001 #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define all(in) in.begin(), in.end() template <class T, class S> void cmin(T &a, const S &b) { if (a > b) a = b; } template <class T, class S> void cmax(T &a, const S &b) { if (a < b) a = b; } #define MAX 9999999 using namespace std; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; int main() { int n; int ans = 0; while (cin >> n, n) { int hoge = 1000 - n; int a = hoge / 500; hoge -= a * 500; ans += a; a = hoge / 100; hoge -= a * 100; ans += a; a = hoge / 50; hoge -= a * 50; ans += a; a = hoge / 10; hoge -= a * 10; ans += a; a = hoge / 5; ans += a; hoge -= a * 5; cout << ans + hoge << endl; } }
#include <algorithm> #include <array> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define vi vector<int> #define vvi vector<vector<int>> #define ll long long int #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vc vector<char> #define vs vector<string> #define ld long double #define INF 1e9 #define EPS 0.0000000001 #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define all(in) in.begin(), in.end() template <class T, class S> void cmin(T &a, const S &b) { if (a > b) a = b; } template <class T, class S> void cmax(T &a, const S &b) { if (a < b) a = b; } #define MAX 9999999 using namespace std; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; int main() { int n; int ans = 0; while (cin >> n, n) { ans = 0; int hoge = 1000 - n; int a = hoge / 500; hoge -= a * 500; ans += a; a = hoge / 100; hoge -= a * 100; ans += a; a = hoge / 50; hoge -= a * 50; ans += a; a = hoge / 10; hoge -= a * 10; ans += a; a = hoge / 5; ans += a; hoge -= a * 5; cout << ans + hoge << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
317
#include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); int n[6], count = 0, coin[] = {500, 100, 50, 10, 5}; for (int i = 0; i < 6; i++) { cin >> n[i]; if (!n[i]) break; } for (int i = 0; i < 6; i++) { if (n[i] == 0) break; int s = 1000 - n[i]; for (int j = 0; j < 5; j++) { int m = s / coin[j]; count += m; s -= m * coin[j]; } count += s; cout << count << endl; } return 0; }
#include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); int n[6], count = 0, coin[] = {500, 100, 50, 10, 5}; for (int i = 0; i < 6; i++) { cin >> n[i]; if (!n[i]) break; } for (int i = 0; i < 6; i++) { if (n[i] == 0) break; int s = 1000 - n[i]; for (int j = 0; j < 5; j++) { int m = s / coin[j]; count += m; s -= m * coin[j]; } count += s; cout << count << endl; count = 0; } return 0; }
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
1
167
#include <iostream> using namespace std; int main() { int x; int ans; cin >> x; while (x != 0) { x = 1000 - x; ans = 0; ans += x / 500; x = x % 500; ans += x / 100; x = x % 100; ans += x / 50; x = x % 50; ans += x / 10; x = x % 10; ans += x / 5; x = x % 5; ans += x; cout << ans; cin >> x; } return 0; }
#include <iostream> using namespace std; int main() { int x; int ans; cin >> x; while (x != 0) { x = 1000 - x; ans = 0; ans += x / 500; x = x % 500; ans += x / 100; x = x % 100; ans += x / 50; x = x % 50; ans += x / 10; x = x % 10; ans += x / 5; x = x % 5; ans += x; cout << ans << endl; cin >> x; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
115
#include <bits/stdc++.h> using namespace std; #define llong long long #define inf 999999999 #define mp make_pair #define pb push_back #define fn fill_n typedef pair<int, int> P; typedef pair<P, int> PP; typedef pair<PP, int> PPP; typedef struct data { int now; int cost; } data; int nh[4] = {1, 0, -1, 0}; int nw[4] = {0, 1, 0, -1}; int main() { int a, b; while (cin >> a) { b = 1000 - a; int ret = 0; while (b != 0) { if (b >= 500) { ret += b / 500; b %= 500; } else if (b >= 100) { ret += b / 100; b %= 100; } else if (b >= 50) { ret += b / 50; b %= 50; } else if (b >= 10) { ret += b / 10; b %= 10; } else if (b >= 5) { ret += b / 5; b %= 5; } else { ret += b; b = 0; } } cout << ret << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define llong long long #define inf 999999999 #define mp make_pair #define pb push_back #define fn fill_n typedef pair<int, int> P; typedef pair<P, int> PP; typedef pair<PP, int> PPP; typedef struct data { int now; int cost; } data; int nh[4] = {1, 0, -1, 0}; int nw[4] = {0, 1, 0, -1}; int main() { int a, b; while (cin >> a, a) { b = 1000 - a; int ret = 0; while (b != 0) { if (b >= 500) { ret += b / 500; b %= 500; } else if (b >= 100) { ret += b / 100; b %= 100; } else if (b >= 50) { ret += b / 50; b %= 50; } else if (b >= 10) { ret += b / 10; b %= 10; } else if (b >= 5) { ret += b / 5; b %= 5; } else { ret += b; b = 0; } } cout << ret << endl; } return 0; }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
1
245
#include <algorithm> #include <array> #include <cmath> #include <complex> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> int main() { int a[5], sum[5] = {0}; int i = 0; while (a[i]) { std::cin >> a[i]; if (a[i] == 0) { break; } i++; } i = 0; while (a[i] != 0) { sum[i] += (1000 - a[i]) / 500; a[i] = (1000 - a[i]) % 500; sum[i] += a[i] / 100; a[i] = a[i] % 100; sum[i] += a[i] / 50; a[i] = a[i] % 50; sum[i] += a[i] / 10; a[i] = a[i] % 10; sum[i] += a[i] / 5; a[i] = a[i] % 5; sum[i] += a[i]; i++; } for (int j = 0; j < i; j++) { std::cout << sum[j] << std::endl; } return 0; }
#include <algorithm> #include <array> #include <cmath> #include <complex> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> int main() { int a[6], sum[5] = {0}; int i = 0; while (1) { std::cin >> a[i]; if (a[i] == 0) { break; } i++; } i = 0; while (a[i] != 0) { sum[i] += (1000 - a[i]) / 500; a[i] = (1000 - a[i]) % 500; sum[i] += a[i] / 100; a[i] = a[i] % 100; sum[i] += a[i] / 50; a[i] = a[i] % 50; sum[i] += a[i] / 10; a[i] = a[i] % 10; sum[i] += a[i] / 5; a[i] = a[i] % 5; sum[i] += a[i]; i++; } for (int j = 0; j < i; j++) { std::cout << sum[j] << std::endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 52, 15, 339, 51, 69, 28, 22], ["-", 0, 52, 15, 339, 51, 69, 341, 342, 0, 70], ["-", 0, 52, 15, 339, 51, 69, 341, 342, 0, 22], ["-", 0, 52, 15, 339, 51, 69, 341, 342, 0, 73], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 51, 13]]
1
268
#include <iostream> using namespace std; int main() { int value, change; int coins; while (1) { cin >> value; if (value == 0) break; coins = 0; change = 1000 - value; coins += change / 500; change %= 500; coins += change / 100; change %= 100; coins += change / 50; change %= 50; coins += change / 10; change %= 10; coins += change / 5; change %= 5; coins += change / 1; change %= 1; cout << coins; } return 0; }
#include <iostream> using namespace std; int main() { int value, change; int coins; while (1) { cin >> value; if (value == 0) break; coins = 0; change = 1000 - value; coins += change / 500; change %= 500; coins += change / 100; change %= 100; coins += change / 50; change %= 50; coins += change / 10; change %= 10; coins += change / 5; change %= 5; coins += change / 1; change %= 1; cout << coins << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
115
#include <iostream> using namespace std; int main() { int money; while (cin >> money && money != 0) { int count = 0; int res = 1000 - money; for (int i = 0; i < 3; i++) { // cout << res << endl; count += res % 10; if (res % 10 > 5) { count -= 4; } res /= 10; } cout << count << endl; } }
#include <iostream> using namespace std; int main() { int money; while (cin >> money && money != 0) { int count = 0; int res = 1000 - money; for (int i = 0; i < 3; i++) { // cout << res << endl; count += res % 10; if (res % 10 > 4) { count -= 4; } res /= 10; } cout << count << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
86
#include <cstdio> int main() { while (1) { int num, n = 0, i = 0, a = 0, b = 0; scanf("%d", &num); if (num == 0) break; n = 1000 - num; if (n >= 500) { i++; n = (n - 500); } if (n >= 100) { a = n / 100; i = a + i; n = n % 100; } if (n >= 51) { i++; n = (n - 50); } if (n >= 11) { b = n / 10; i = b + i; n = n % 10; } if (n >= 6) { i++; n = (n - 5); } i = (i + n); printf("%d\n", i); } return 0; }
#include <cstdio> int main() { while (1) { int num, n = 0, i = 0, a = 0, b = 0; scanf("%d", &num); if (num == 0) break; n = 1000 - num; if (n >= 500) { i++; n = (n - 500); } if (n >= 100) { a = n / 100; i = a + i; n = n % 100; } if (n >= 50) { i++; n = (n - 50); } if (n >= 10) { b = n / 10; i = b + i; n = n % 10; } if (n >= 5) { i++; n = (n - 5); } i = (i + n); printf("%d\n", i); } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
187
#include <algorithm> #include <cctype> #include <iostream> #include <map> #include <queue> #include <stdio.h> #include <string.h> using namespace std; int main(int argc, char const *argv[]) { int money; while (cin >> money) { int coin_count = 0; int rest = 1000; rest -= money; int tmp = 0; coin_count += rest / 500; rest = rest % 500; coin_count += rest / 100; rest = rest % 100; coin_count += rest / 50; rest = rest % 50; coin_count += rest / 10; rest = rest % 10; coin_count += rest / 5; rest = rest % 5; coin_count += rest / 1; cout << coin_count << endl; } return 0; }
#include <algorithm> #include <cctype> #include <iostream> #include <map> #include <queue> #include <stdio.h> #include <string.h> using namespace std; int main(int argc, char const *argv[]) { int money; while (cin >> money, money) { int coin_count = 0; int rest = 1000; rest -= money; int tmp = 0; coin_count += rest / 500; rest = rest % 500; coin_count += rest / 100; rest = rest % 100; coin_count += rest / 50; rest = rest % 50; coin_count += rest / 10; rest = rest % 10; coin_count += rest / 5; rest = rest % 5; coin_count += rest / 1; cout << coin_count << endl; } return 0; }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
1
138
#include <iostream> using namespace std; int coins[] = {500, 100, 50, 10, 5, 1}; int main() { int n; while (cin >> n && n) { cin >> n; int remaind = 1000 - n; int ans = 0; for (int i = 0; i < 6; i++) { ans += remaind / coins[i]; remaind %= coins[i]; } cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int coins[] = {500, 100, 50, 10, 5, 1}; int main() { int n; while (cin >> n && n) { int remaind = 1000 - n; int ans = 0; for (int i = 0; i < 6; i++) { ans += remaind / coins[i]; remaind %= coins[i]; } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 152], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
101
#include <algorithm> #include <array> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { const array<int, 6> coins = {500, 100, 50, 10, 5, 1}; while (true) { int n; cin >> n; if (n == 0) break; n = 1000 - n; int count = 0; for (auto coin : coins) { if (n > coin) { count += (n / coin); n %= coin; } } cout << count << endl; } return 0; }
#include <algorithm> #include <array> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { const array<int, 6> coins = {500, 100, 50, 10, 5, 1}; while (true) { int n; cin >> n; if (n == 0) break; n = 1000 - n; int count = 0; for (auto coin : coins) { if (n >= coin) { count += (n / coin); n %= coin; } } cout << count << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
113
O=[500,100,50,10,1] while (i=gets.to_i)!=0 sum = 0 i = 1000 - i O.each do |o| sum += i/o i %= o end puts sum end
O=[500,100,50,10,5,1] while (i=gets.to_i)!=0 sum = 0 i = 1000 - i O.each do |o| sum += i/o i %= o end puts sum end
[["+", 36, 36, 0, 493, 0, 662, 12, 516, 0, 612], ["+", 36, 36, 0, 493, 0, 662, 12, 516, 0, 21]]
4
50
import sys x=sys.stdin.read().split() def otsuri(x): a=0 y=1000-x if y==1000: return'' else: while y>=0: if y-500<0: break else: y=y-500 a=a+1 while y>=0: if y-100<0: break else: y=y-100 a=a+1 while y>=0: if y-50<0: break else: y=y-50 a=a+1 while y>=0: if y-10<0: break else: y=y-10 a=a+1 while y>=0: if y-5<0: break else: y=y-5 a=a+1 while y>=0: if y-1<0: break else: y=y-1 a=a+1 return a x=list(map(int,x)) for change in x: print(otsuri(change))
import sys x=sys.stdin.read().split() def otsuri(x): a=0 y=1000-x if y==1000: sys.exit(0) else: while y>=0: if y-500<0: break else: y=y-500 a=a+1 while y>=0: if y-100<0: break else: y=y-100 a=a+1 while y>=0: if y-50<0: break else: y=y-50 a=a+1 while y>=0: if y-10<0: break else: y=y-10 a=a+1 while y>=0: if y-5<0: break else: y=y-5 a=a+1 while y>=0: if y-1<0: break else: y=y-1 a=a+1 return a x=list(map(int,x)) for change in x: print(otsuri(change))
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 0, 57, 64, 196, 0, 37, 0, 557, 0, 654], ["-", 0, 57, 64, 196, 0, 37, 0, 557, 0, 655], ["+", 64, 196, 0, 1, 0, 652, 63, 319, 500, 22], ["+", 64, 196, 0, 1, 0, 652, 63, 319, 0, 131], ["+", 64, 196, 0, 1, 0, 652, 63, 319, 319, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 612], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
214
taro_spend = [] spend_num = 0 for i in range(5): taro_spend.append(int(input())) if taro_spend[i] == 0: taro_spend.pop() break spend_num += 1 changes = [1000 - taro_spend[i] for i in range(spend_num)] print(changes) for change in changes: change_coin = 0 if change >= 500: change -= 500 change_coin += 1 if change >= 100: while change >= 100: change -= 100 change_coin += 1 if change >= 50: change -= 50 change_coin += 1 if change >= 10: while change >= 10: change -= 10 change_coin += 1 if change >= 5: change -= 5 change_coin += 1 if change >= 1: while change >= 1: change -= 1 change_coin += 1 print(change_coin)
taro_spend = [] spend_num = 0 for i in range(5): taro_spend.append(int(input())) if taro_spend[i] == 0: taro_spend.pop() break spend_num += 1 changes = [1000 - taro_spend[i] for i in range(spend_num)] for change in changes: change_coin = 0 if change >= 500: change -= 500 change_coin += 1 if change >= 100: while change >= 100: change -= 100 change_coin += 1 if change >= 50: change -= 50 change_coin += 1 if change >= 10: while change >= 10: change -= 10 change_coin += 1 if change >= 5: change -= 5 change_coin += 1 if change >= 1: while change >= 1: change -= 1 change_coin += 1 print(change_coin)
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
157
coins = [500, 100, 50, 10, 5, 1] def count(x, y): ret = 0 while x >= y: x -= y ret += 1 return ret while True: n = eval(input()) if n == 0: break ans = 0 n = 1000 - n for val in coins: n, t = count(n, val) ans += t print(ans)
coins = (500, 100, 50, 10, 5, 1) def count(x, y): ret = 0 while x >= y: x -= y ret += 1 return x, ret while True: n = eval(input()) if n == 0: break ans = 0 n = 1000 - n for val in coins: n, t = count(n, val) ans += t print(ans)
[["-", 0, 656, 0, 1, 0, 662, 12, 634, 0, 70], ["+", 0, 656, 0, 1, 0, 662, 12, 660, 0, 24], ["-", 0, 656, 0, 1, 0, 662, 12, 634, 0, 73], ["+", 0, 656, 0, 1, 0, 662, 12, 660, 0, 25], ["+", 0, 14, 8, 196, 0, 37, 0, 432, 0, 22], ["+", 0, 14, 8, 196, 0, 37, 0, 432, 0, 21]]
5
86
c = [500,100,50,10,5,1] while True: e = int(input()) if e == 0: break i,m = 0,0 while e > 0: if e >= c[i]: e -= c[i] m += 1 else: i += 1 print(m)
c = [500,100,50,10,5,1] while True: e = int(input()) if e == 0: break e = 1000-e i,m = 0,0 while e > 0: if e >= c[i]: e -= c[i] m += 1 else: i += 1 print(m)
[["+", 0, 52, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 31, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 33], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 12, 22]]
5
70
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner in = new Scanner(System.in); while (true) { if (in.hasNext() == false) { break; } String text = in.next(); char[] s = text.toCharArray(); int joi = 0; int ioi = 0; for (int i = 0; i < text.length() - 2; i++) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') { joi++; } else if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') { ioi++; } } System.out.println(joi); System.out.print(ioi); } } }
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner in = new Scanner(System.in); while (true) { if (in.hasNext() == false) { break; } String text = in.next(); char[] s = text.toCharArray(); int joi = 0; int ioi = 0; for (int i = 0; i < text.length() - 2; i++) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') { joi++; } else if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') { ioi++; } } System.out.println(joi); System.out.println(ioi); } } }
[["-", 0, 52, 8, 196, 0, 1, 0, 492, 141, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 492, 141, 22]]
3
190
#include <stdio.h> #include <string.h> char str[10001]; int main(void) { while (scanf("%s", str) != EOF) { int joi = 0; int ioi = 0; int i; for (i = 0; i < strlen(str) - 2; i++) { if (strncmp(str, "JOI", 3) == 0) { joi++; } if (strncmp(str, "IOI", 3) == 0) { ioi++; } } printf("%d\n", joi); printf("%d\n", ioi); } return 0; }
#include <stdio.h> #include <string.h> char str[10001]; int main(void) { while (scanf("%s", str) != EOF) { int joi = 0; int ioi = 0; int i; for (i = 0; i < strlen(str) - 2; i++) { if (strncmp(str + i, "JOI", 3) == 0) { joi++; } if (strncmp(str + i, "IOI", 3) == 0) { ioi++; } } printf("%d\n", joi); printf("%d\n", ioi); } return 0; }
[["+", 0, 16, 31, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 16, 31, 2, 3, 4, 0, 16, 12, 22]]
0
128
#include <stdio.h> int main(void) { int i; int counti, countj; char a[10000]; while (scanf("%s", a) != EOF) { counti = 0; countj = 0; for (i = 0; a[i] != '\0'; i++) { if (a[i + 1] == 'O' && a[i + 2] == 'I') { if (a[i] == 'I') counti++; if (a[i] == 'J') countj++; } } printf("%d\n%d\n", counti, countj); } return 0; }
#include <stdio.h> int main(void) { int i; int counti, countj; char a[10000]; while (scanf("%s", a) != EOF) { counti = 0; countj = 0; for (i = 0; a[i] != '\0'; i++) { if (a[i + 1] == 'O' && a[i + 2] == 'I') { if (a[i] == 'I') counti++; if (a[i] == 'J') countj++; } } printf("%d\n%d\n", countj, counti); } return 0; }
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
0
137
#include <stdio.h> int main() { char ch[10001]; int i = 0, joi = 0, ioi = 0; while (scanf("%s\n", &ch) != EOF) { while (1) { if (ch[i] == '\0') break; if (ch[i] == 'J' && ch[i + 1] == 'O' && ch[i + 2] == 'I') joi++; if (ch[i] == 'I' && ch[i + 1] == 'O' && ch[i + 2] == 'I') joi++; i++; } i = 0; printf("%d\n%d\n", joi, ioi); joi = 0; ioi = 0; } return 0; }
#include <stdio.h> int main() { char ch[10001]; int i = 0, joi = 0, ioi = 0; while (scanf("%s\n", &ch) != EOF) { while (1) { if (ch[i] == '\0') break; if (ch[i] == 'J' && ch[i + 1] == 'O' && ch[i + 2] == 'I') joi++; if (ch[i] == 'I' && ch[i + 1] == 'O' && ch[i + 2] == 'I') ioi++; i++; } i = 0; printf("%d\n%d\n", joi, ioi); joi = 0; ioi = 0; } return 0; }
[["-", 8, 9, 0, 57, 64, 1, 0, 27, 28, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 27, 28, 22]]
0
167
#include <stdio.h> #include <string.h> #define S_MAX 10000 char s[S_MAX + 1]; void solve(const int l) { int j = 0, i = 0; int n = 1; while (n + 1 < l) { if (s[n] == 'O' || s[n + 1] == 'I') { switch (s[n - 1]) { case 'J': j++; break; case 'I': i++; break; } } n++; } printf("%d\n%d\n", j, i); return; } int main(void) { while (scanf("%s", s) != EOF) { solve(strlen(s)); } return 0; }
#include <stdio.h> #include <string.h> #define S_MAX 10000 char s[S_MAX + 1]; void solve(const int l) { int j = 0, i = 0; int n = 1; while (n + 1 < l) { if (s[n] == 'O' && s[n + 1] == 'I') { switch (s[n - 1]) { case 'J': j++; break; case 'I': i++; break; } } n++; } printf("%d\n%d\n", j, i); return; } int main(void) { while (scanf("%s", s) != EOF) { solve(strlen(s)); } return 0; }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 106], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98]]
0
155
#include <stdio.h> #include <string.h> int main() { char string[10000]; int i, JOIcount, IOIcount, strlong; while (scanf("%s", &string) != EOF) { JOIcount = 0; IOIcount = 0; strlong = strlen(string); for (i = 0; i < strlong - 2; i++) { if (string[i] == 'J') { if (string[i + 1] == 'O') { if (string[i + 2] == 'I') { JOIcount += 1; } } } else if (string[i] == 'I') { if (string[i + 1] == 'O') { if (string[i + 2] == 'I') { IOIcount += 1; } } } } } printf("%d\n%d\n", JOIcount, IOIcount); return 0; }
#include <stdio.h> #include <string.h> int main() { char string[10000]; int i, JOIcount, IOIcount, strlong; while (scanf("%s", &string) != EOF) { JOIcount = 0; IOIcount = 0; strlong = strlen(string); for (i = 0; i < strlong - 2; i++) { if (string[i] == 'J') { if (string[i + 1] == 'O') { if (string[i + 2] == 'I') { JOIcount += 1; } } } else if (string[i] == 'I') { if (string[i + 1] == 'O') { if (string[i + 2] == 'I') { IOIcount += 1; } } } } printf("%d\n%d\n", JOIcount, IOIcount); } return 0; }
[["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
0
185
#include <stdio.h> int main() { char a[1001]; int i = 0; int b; int c = 0, c1 = 0; while (scanf("%s", &a) != EOF) { c = 0; c1 = 0; i = 0; while (a[i + 2] != EOF) { if (a[i] == 'J' && a[i + 1] == 'O' && a[i + 2] == 'I') { c++; } if (a[i] == 'I' && a[i + 1] == 'O' && a[i + 2] == 'I') { c1++; } i++; } for (b = 0; b < 10000; b++) { a[b] = 0; } printf("%d\n%d\n", c, c1); } return 0; }
#include <stdio.h> int main() { char a[10001]; int i = 0; int b; int c = 0, c1 = 0; while (scanf("%s", &a) != EOF) { c = 0; c1 = 0; i = 0; while (a[i + 2] != EOF) { if (a[i] == 'J' && a[i + 1] == 'O' && a[i + 2] == 'I') { c++; } if (a[i] == 'I' && a[i + 1] == 'O' && a[i + 2] == 'I') { c1++; } i++; } for (b = 0; b < 10000; b++) { a[b] = 0; } printf("%d\n%d\n", c, c1); } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
0
190
#include <iostream> #include <string> using namespace std; int main() { string ss; cin >> ss; int j = 0, k = 0; for (int i = 1; i < ss.length() - 1; i++) { if (ss[i] == 'O') { if (ss[i + 1] == 'I') { if (ss[i - 1] == 'J') j++; if (ss[i - 1] == 'I') k++; } } } cout << j << "\n" << k << "\n"; return 0; }
#include <iostream> #include <string> using namespace std; int main() { string ss; while (cin >> ss) { int j = 0, k = 0; for (int i = 1; i < ss.length() - 1; i++) { if (ss[i] == 'O') { if (ss[i + 1] == 'I') { if (ss[i - 1] == 'J') j++; if (ss[i - 1] == 'I') k++; } } } cout << j << "\n" << k << "\n"; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
129
#include <cstdio> #include <cstring> using namespace std; int main() { char str[100000]; while (scanf("%s", str) != EOF) { int joi = 0; int ioi = 0; for (int i = 0; i < strlen(str) - 2; i++) { if (str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I') { joi++; } if (str[i] == 'I' && str[i + 1] && 'O' && str[i + 2] == 'I') { ioi++; } } printf("%d\n", joi); printf("%d\n", ioi); } return (0); }
#include <cstdio> #include <cstring> using namespace std; int main() { char str[100000]; while (scanf("%s", str) != EOF) { int joi = 0; int ioi = 0; for (int i = 0; i < strlen(str) - 2; i++) { if (str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I') { joi++; } if (str[i] == 'I' && str[i + 1] == 'O' && str[i + 2] == 'I') { ioi++; } } printf("%d\n", joi); printf("%d\n", ioi); } return (0); }
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 98], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 60]]
1
167
#include <iostream> #include <string> using namespace std; int main() { string s; int i, joi, ioi; while (cin >> s, !cin.eof()) { joi = 0; ioi = 0; for (i = 0; i < s.size(); i++) { if (s[i] == 'J') { if (s[i + 1] == 'O') { if (s[i + 2] == 'I') { joi++; i += 1; } } } if (s[i] == 'I') { if (s[i + 1] == 'O') { if (s[i + 2] == 'I') { ioi++; i += 1; } } } } } cout << joi << endl << ioi << endl; }
#include <iostream> #include <string> using namespace std; int main() { string s; int i, joi, ioi; while (cin >> s, !cin.eof()) { joi = 0; ioi = 0; for (i = 0; i < s.size() - 2; i++) { if (s[i] == 'J') { if (s[i + 1] == 'O') { if (s[i + 2] == 'I') { joi++; i += 1; } } } if (s[i] == 'I') { if (s[i + 1] == 'O') { if (s[i + 2] == 'I') { ioi++; i += 1; } } } } cout << joi << endl; cout << ioi << endl; } }
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 0, 57, 64, 9, 0, 57, 64, 9, 0, 46], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
176
#include <iostream> #include <string> using namespace std; int main() { string a; while (cin >> a) { int joi = 0, ioi = 0; a += "XX"; for (int i = 0; i < a.size(); i++) { if (a[i] == 'X') break; if (a[i] == 'J' && a[i + 1] == 'O' && a[i + 2] == 'I') joi++; if (a[i] == 'I' && a[i + 1] == 'O' && a[i + 2] == 'I') ioi++; } cout << joi << endl << ioi << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { string a; while (cin >> a) { int joi = 0, ioi = 0; a += "xx"; for (int i = 0; i < a.size(); i++) { if (a[i] == 'x') break; if (a[i] == 'J' && a[i + 1] == 'O' && a[i + 2] == 'I') joi++; if (a[i] == 'I' && a[i + 1] == 'O' && a[i + 2] == 'I') ioi++; } cout << joi << endl << ioi << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["-", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125], ["+", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125]]
1
158
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main() { char c[10001]; while (scanf("%s", c) != EOF) { int ioi_cnt = 0, joi_cnt = 0; for (int i = 0; i < strlen(c) - 2; i++) { if (c[i + 1] == 'O' && c[i + 2] == 'I') { if (c[i] == 'I') ioi_cnt++; if (c[i] == 'J') joi_cnt++; } } cout << ioi_cnt << endl << joi_cnt << endl; } }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main() { char c[10001]; while (scanf("%s", c) != EOF) { int ioi_cnt = 0, joi_cnt = 0; for (int i = 0; i < strlen(c) - 2; i++) { if (c[i + 1] == 'O' && c[i + 2] == 'I') { if (c[i] == 'I') ioi_cnt++; if (c[i] == 'J') joi_cnt++; } } cout << joi_cnt << endl << ioi_cnt << endl; } }
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
131
#include <iostream> #include <string> int main() { std::string s; std::cin >> s; int JOI = 0, IOI = 0; for (int i = 0; i < s.size() - 2; ++i) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') JOI++; if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') IOI++; } std::cout << JOI << std::endl << IOI << std::endl; }
#include <iostream> #include <string> int main() { std::string s; while (std::cin >> s) { int JOI = 0, IOI = 0; for (int i = 0; i < s.size() - 2; ++i) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') JOI++; if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') IOI++; } std::cout << JOI << std::endl << IOI << std::endl; } }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
140
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i, n) for (int i = 0; i < (n); i++) #define all(a) (a).begin(), (a).end() #define pb push_back #define x first #define y second int main() { string s; cin >> s; int J = 0, I = 0; rep(i, s.size() - 2) { if (s.substr(i, 3) == "JOI") J++; if (s.substr(i, 3) == "IOI") I++; } cout << J << endl << I << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i, n) for (int i = 0; i < (n); i++) #define all(a) (a).begin(), (a).end() #define pb push_back #define x first #define y second int main() { string s; while (cin >> s) { int J = 0, I = 0; rep(i, s.size() - 2) { if (s.substr(i, 3) == "JOI") J++; if (s.substr(i, 3) == "IOI") I++; } cout << J << endl << I << endl; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
178
#include <iostream> using namespace std; int main() { char s[10001] = {}; while (1) { s[0] = ' '; cin >> s; if (s[0] == ' ') { return 0; } int i = 0, ioi = 0, j = 0, joi = 0; for (int k = 0; s[k] != '\0'; k++) { switch (j) { case 1: if (s[k] == 'O') { j = 2; } else { j = 0; } break; case 2: if (s[k] = 'I') { j = 0; joi++; } else { j = 0; } } if (s[k] == 'J') { j = 1; } switch (i) { case 1: if (s[k] == 'O') { i = 2; } else { i = 0; } break; case 2: if (s[k] = 'I') { ioi++; } else { i = 0; } } if (s[k] == 'I') { i = 1; } } cout << joi << endl; cout << ioi << endl; } }
#include <iostream> using namespace std; int main() { char s[10001] = {}; while (1) { s[0] = ' '; cin >> s; if (s[0] == ' ') { return 0; } int i = 0, ioi = 0, j = 0, joi = 0; for (int k = 0; s[k] != '\0'; k++) { switch (j) { case 1: if (s[k] == 'O') { j = 2; } else { j = 0; } break; case 2: if (s[k] == 'I') { j = 0; joi++; } else { j = 0; } } if (s[k] == 'J') { j = 1; } switch (i) { case 1: if (s[k] == 'O') { i = 2; } else { i = 0; } break; case 2: if (s[k] == 'I') { ioi++; } else { i = 0; } } if (s[k] == 'I') { i = 1; } } cout << joi << endl; cout << ioi << endl; } }
[["-", 0, 100, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 0, 100, 0, 57, 15, 339, 51, 16, 17, 60]]
1
266