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
change_count
int64
0
100
#include <bits/stdc++.h> using namespace std; int a, b, ans; void dfs(int n, int s, int bit, int bef); int main() { cin >> a >> b; while (a != 0 && b != 0) { ans = 0; dfs(0, 0, 0, -1); cout << ans << endl; cin >> a >> b; } return (0); } void dfs(int n, int s, int bit, int bef) { if (n == a) { if (s == b) ans++; } else { for (int i = 0; i <= 9; i++) { if (((1 << i) & bit) == 0 && bef < i) { dfs(n + 1, s + i, bit | (1 << i), i); } } } }
#include <bits/stdc++.h> using namespace std; int a, b, ans; void dfs(int n, int s, int bit, int bef); int main() { cin >> a >> b; while (a != 0 || b != 0) { ans = 0; dfs(0, 0, 0, -1); cout << ans << endl; cin >> a >> b; } return (0); } void dfs(int n, int s, int bit, int bef) { if (n == a) { if (s == b) ans++; } else { for (int i = 0; i <= 9; i++) { if (((1 << i) & bit) == 0 && bef < i) { dfs(n + 1, s + i, bit | (1 << i), i); } } } }
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 106]]
1
179
2
#include <iostream> int Judge(int n, int remain, int start) { if (n == 1) { if (remain < 0) { return 0; } if (remain < start) { return 0; } if (remain > 9) { return 0; } return 1; } else { int ret = 0; for (int i = start; i < 9; ++i) { ret += Judge(n - 1, remain - i, i + 1); } return ret; } } int main() { int n, s; while (std::cin >> n >> s) { if (n == 0 && s == 0) { break; } std::cout << Judge(n, s, 0); } return 0; }
#include <iostream> int Judge(int n, int remain, int start) { if (n == 1) { if (remain < 0) { return 0; } if (remain < start) { return 0; } if (remain > 9) { return 0; } return 1; } else { int ret = 0; for (int i = start; i < 9; ++i) { ret += Judge(n - 1, remain - i, i + 1); } return ret; } } int main() { int n, s; while (std::cin >> n >> s) { if (n == 0 && s == 0) { break; } std::cout << Judge(n, s, 0) << std::endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 1, 0, 16, 12, 343, 345, 348], ["+", 8, 9, 0, 1, 0, 16, 12, 343, 0, 349], ["+", 8, 9, 0, 1, 0, 16, 12, 343, 141, 22]]
1
157
4
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; using LL = long long; using ULL = unsigned long long; constexpr int INF = 2147483647; constexpr int HINF = INF / 2; constexpr double DINF = 100000000000000000.0; constexpr double HDINF = 50000000000000000.0; constexpr long long LINF = 9223372036854775807; constexpr long long HLINF = 4500000000000000000; const double PI = acos(-1); int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; template <typename T_char> T_char TL(T_char cX) { return tolower(cX); }; template <typename T_char> T_char TU(T_char cX) { return toupper(cX); }; #define ALL(x) (x).begin(), (x).end() #define UNIQ(c) (c).erase(unique(ALL((c))), (c).end()) #define LOWER(s) transform(ALL((s)), (s).begin(), TL<char>) #define UPPER(s) transform(ALL((s)), (s).begin(), TU<char>) #define mp make_pair #define eb emplace_back #define FOR(i, a, b) for (LL i = (a); i < (b); i++) #define RFOR(i, a, b) for (LL i = (a); i >= (b); i--) #define REP(i, n) FOR(i, 0, n) #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0) int N, S; int ans = 0; void dfs(int s, int i, int cnt) { if (cnt == N && s == S) { ans++; return; } else if (cnt == N || s >= S || i == 10) { return; } else { dfs(s + i, i + 1, cnt + 1); dfs(s, i + 1, cnt); } } int main() { while (cin >> N >> S && (N != 0 || S != 0)) { ans = 0; dfs(0, 0, 0); cout << ans << endl; } }
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; using LL = long long; using ULL = unsigned long long; constexpr int INF = 2147483647; constexpr int HINF = INF / 2; constexpr double DINF = 100000000000000000.0; constexpr double HDINF = 50000000000000000.0; constexpr long long LINF = 9223372036854775807; constexpr long long HLINF = 4500000000000000000; const double PI = acos(-1); int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; template <typename T_char> T_char TL(T_char cX) { return tolower(cX); }; template <typename T_char> T_char TU(T_char cX) { return toupper(cX); }; #define ALL(x) (x).begin(), (x).end() #define UNIQ(c) (c).erase(unique(ALL((c))), (c).end()) #define LOWER(s) transform(ALL((s)), (s).begin(), TL<char>) #define UPPER(s) transform(ALL((s)), (s).begin(), TU<char>) #define mp make_pair #define eb emplace_back #define FOR(i, a, b) for (LL i = (a); i < (b); i++) #define RFOR(i, a, b) for (LL i = (a); i >= (b); i--) #define REP(i, n) FOR(i, 0, n) #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0) int N, S; int ans; void dfs(int s, int i, int cnt) { if (cnt == N && s == S) { ans++; return; } else if (cnt == N || s > S || i == 10) { return; } else { dfs(s + i, i + 1, cnt + 1); dfs(s, i + 1, cnt); } } int main() { while (cin >> N >> S && (N != 0 || S != 0)) { ans = 0; dfs(0, 0, 0); cout << ans << endl; } }
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 0, 32], ["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 20], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 47]]
1
373
4
#include <iostream> using namespace std; int rec(int n, int s, int num) { if (n == 0 && s == 0) return 1; if (n == 0 || num == 19) return 0; return rec(n, s, num + 1) + rec(n - 1, s - num, num + 1); } signed main() { int n, s; while (cin >> n >> s, n || s) { cout << rec(n, s, 0) << endl; } return (0); }
#include <iostream> using namespace std; int rec(int n, int s, int num) { if (n == 0 && s == 0) return 1; if (n == 0 || num == 10) return 0; return rec(n, s, num + 1) + rec(n - 1, s - num, num + 1); } signed main() { int n, s; while (cin >> n >> s, n || s) { cout << rec(n, s, 0) << endl; } return (0); }
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
116
2
#include <iostream> using namespace std; int c; int sub(int n, int x, int s, int sum) { int i; if (n == 0) { if (s == sum) { c++; } return 0; } for (i = x; i < 10 - n; i++) { sub(n - 1, i + 1, s, sum + i); } } int main(void) { int i, n, s, sum; while (1) { cin >> n >> s; if (n == 0 && s == 0) { break; } c = 0; sub(n, 0, s, 0); cout << c << endl; } return 0; }
#include <iostream> using namespace std; int c; int sub(int n, int x, int s, int sum) { int i; if (n == 0) { if (s == sum) { c++; } return 0; } for (i = x; i <= 10 - n; i++) { sub(n - 1, i + 1, s, sum + i); } } int main(void) { int i, n, s, sum; while (1) { cin >> n >> s; if (n == 0 && s == 0) { break; } c = 0; sub(n, 0, s, 0); cout << c << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
151
2
#include <iostream> using namespace std; int n, s; int cou; void dfs(int i, int sum, int num_of_add) { if (sum == s && num_of_add == n) { cou++; return; } if (n == num_of_add || i == 10) return; dfs(i + 1, sum, num_of_add); dfs(i + 1, sum + i, num_of_add + 1); } int main() { while (cin >> n >> s, n != 0 && s != 0) { cou = 0; dfs(0, 0, 0); cout << cou << endl; } }
#include <iostream> using namespace std; int n, s; int cou; void dfs(int i, int sum, int num_of_add) { if (sum == s && num_of_add == n) { cou++; return; } if (n == num_of_add || i == 10) return; dfs(i + 1, sum, num_of_add); dfs(i + 1, sum + i, num_of_add + 1); } int main() { while (cin >> n >> s, n != 0 || s != 0) { cou = 0; dfs(0, 0, 0); cout << cou << endl; } }
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
1
126
2
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i)) #define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i)) #define repr(i, a, n) for (int(i) = (int)(a); (i) > (int)(n); --(i)) #define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i)) #define SIZE(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define RNG(x, n) &((x)[0]), &((x)[n]) #define SUBIF(a, b, x) ((x) ? (b) : (a)) #define YES cout << "YES" << endl #define NO cout << "NO" << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define yes cout << "yes" << endl; #define no cout << "no" << endl; #define pb push_back #define EPS (1e-20) #define INF 2147483647LL #define MOD 1000000007LL using llint = long long; using VI = std::vector<int>; using PII = std::pair<int, int>; using SI = std::set<int>; using MII = std::map<int, int>; using TIII = std::tuple<int, int, int>; using namespace std; int n, s; int cntBit(int bit) { int cnt = 0; do { cnt += bit & 1; } while (bit /= 2); return cnt; } VI enumComb() { VI comb; rep(i, 0, 1 << 10) if (cntBit(i) == n) comb.pb(i); return comb; } int solve() { int ans = 0; VI comb = enumComb(); for (int x : comb) { int sum = 0; repe(i, 0, 9) if ((x >> i) & 1) sum += i; if (sum == s) ans++; } return ans; } int main() { while (cin >> n >> s, n && s) cout << solve() << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i)) #define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i)) #define repr(i, a, n) for (int(i) = (int)(a); (i) > (int)(n); --(i)) #define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i)) #define SIZE(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define RNG(x, n) &((x)[0]), &((x)[n]) #define SUBIF(a, b, x) ((x) ? (b) : (a)) #define YES cout << "YES" << endl #define NO cout << "NO" << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define yes cout << "yes" << endl; #define no cout << "no" << endl; #define pb push_back #define EPS (1e-20) #define INF 2147483647LL #define MOD 1000000007LL using llint = long long; using VI = std::vector<int>; using PII = std::pair<int, int>; using SI = std::set<int>; using MII = std::map<int, int>; using TIII = std::tuple<int, int, int>; using namespace std; int n, s; int cntBit(int bit) { int cnt = 0; do { cnt += bit & 1; } while (bit /= 2); return cnt; } VI enumComb() { VI comb; rep(i, 0, 1 << 10) if (cntBit(i) == n) comb.pb(i); return comb; } int solve() { int ans = 0; VI comb = enumComb(); for (int x : comb) { int sum = 0; repe(i, 0, 9) if ((x >> i) & 1) sum += i; if (sum == s) ans++; } return ans; } int main() { while (cin >> n >> s, n || s) cout << solve() << endl; return 0; }
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
1
366
2
#include <iostream> #include <vector> using namespace std; int n, k, m; int ans = 0; vector<int> s(10); void bfs(int nn, int sum, int min) { if (nn == 0 && sum == 0) { ans++; return; } for (int i = min; i < 10 && n > 0; i++) { if (sum - i >= 0) { bfs(nn - 1, sum - i, i + 1); } } } int main() { while (cin >> n >> m) { if (n == 0 && m == 0) break; bfs(n, m, 0); cout << ans << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; int n, k, m; int ans = 0; vector<int> s(10); void bfs(int nn, int sum, int min) { if (nn == 0 && sum == 0) { ans++; return; } for (int i = min; i < 10 && n > 0; i++) { if (sum - i >= 0) { bfs(nn - 1, sum - i, i + 1); } } } int main() { while (cin >> n >> m) { if (n == 0 && m == 0) break; bfs(n, m, 0); cout << ans << endl; ans = 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
151
4
#include <iostream> using namespace std; int hoge(int b, int n, int s) { if (n == 1) return (0 <= s && s <= 9 && b <= s) ? 1 : 0; int sum = 0; for (int i = b; i <= 9; ++i) sum += hoge(i + 1, n - 1, s - i); return sum; } int main(void) { int n, s; while (cin >> n >> s && n != 0 && s != 0) { cout << hoge(0, n, s) << endl; } return 0; }
#include <iostream> using namespace std; int hoge(int b, int n, int s) { if (n == 1) return (0 <= s && s <= 9 && b <= s) ? 1 : 0; int sum = 0; for (int i = b; i <= 9; ++i) sum += hoge(i + 1, n - 1, s - i); return sum; } int main(void) { int n, s; while (cin >> n >> s && (n != 0 || s != 0)) { cout << hoge(0, n, s) << endl; } return 0; }
[["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 24], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 25]]
1
130
4
#include <iostream> using namespace std; // n個の重複しない整数(min ~ max)用いてsを表す組み合わせの数 int ci(int n, int s, int min, int max) { if (s < min || n < 1) return 0; if (n == 1) return (s > max) ? 1 : 0; int r = 0; for (int i = min; i < s && i <= max; i++) { r += ci(n - 1, s - i, i + 1, max); } return r; } int main() { while (true) { int n, s; cin >> n >> s; if (!n && !s) break; cout << ci(n, s, 0, 9) << endl; } return 0; }
#include <iostream> using namespace std; // n個の重複しない整数(min ~ max)用いてsを表す組み合わせの数 int ci(int n, int s, int min, int max) { if (s < min || n < 1) return 0; if (n == 1) return (s > max) ? 0 : 1; int r = 0; for (int i = min; i < s && i <= max; i++) { r += ci(n - 1, s - i, i + 1, max); } return r; } int main() { while (true) { int n, s; cin >> n >> s; if (!n && !s) break; cout << ci(n, s, 0, 9) << endl; } return 0; }
[["-", 8, 9, 0, 57, 64, 37, 0, 41, 64, 13], ["-", 8, 9, 0, 57, 64, 37, 0, 41, 0, 102], ["+", 8, 9, 0, 57, 64, 37, 0, 41, 0, 102], ["+", 8, 9, 0, 57, 64, 37, 0, 41, 75, 13]]
1
152
4
#include <iostream> using namespace std; int visit(int n, int s, int x) { int sum = 0; if (n == 0 && s == 0) return 1; if (n > 0) { for (int i = x; i < 10; i++) { if (s - i >= 0) sum += visit(n - 1, s - i, i++); } } return sum; } int main(void) { int n, s; while (cin >> n >> s) { if (n == 0 && s == 0) break; cout << visit(n, s, 0) << endl; } return 0; }
#include <iostream> using namespace std; int visit(int n, int s, int x) { int sum = 0; if (n == 0 && s == 0) return 1; if (n > 0) { for (int i = x; i < 10; i++) { if (s - i >= 0) sum += visit(n - 1, s - i, i + 1); } } return sum; } int main(void) { int n, s; while (cin >> n >> s) { if (n == 0 && s == 0) break; cout << visit(n, s, 0) << endl; } return 0; }
[["-", 0, 11, 12, 2, 3, 4, 0, 27, 17, 29], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13]]
1
139
3
#include <iostream> using namespace std; int main() { int n, s, r, bit; int sum; while (cin >> n >> s, n, s) { r = 0; for (int i = 0; i < (1 << 10); i++) { sum = bit = 0; for (int j = 0; j < 10; j++) if (i & (1 << j)) bit++; if (bit != n) continue; for (int j = 0; j < 10; j++) { if (i & (1 << j)) sum += j; } if (sum == s) r++; } cout << r << endl; } }
#include <iostream> using namespace std; int main() { int n, s, r, bit; int sum; while (cin >> n >> s && n || s) { r = 0; for (int i = 0; i < (1 << 10); i++) { sum = bit = 0; for (int j = 0; j < 10; j++) if (i & (1 << j)) bit++; if (bit != n) continue; for (int j = 0; j < 10; j++) { if (i & (1 << j)) sum += j; } if (sum == s) r++; } cout << r << endl; } }
[["-", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 17, 98], ["-", 0, 52, 15, 339, 51, 34, 12, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 106]]
1
148
4
#include <iostream> using namespace std; int combination(int least, int n, int s) { int sum = 0; if (n == 1) return (least < s && s <= 9) ? 1 : 0; else { int sum = 0; for (int i = least + 1; i <= 9; i++) sum += combination(i, n - 1, s - least); return sum; } }; int main() { while (true) { int n, s; cin >> n; cin >> s; if (n == 0 && s == 0) break; else cout << combination(0, n, s) << endl; } return 0; }
#include <iostream> using namespace std; int combination(int least, int n, int s) { int sum = 0; if (n == 1) return (least < s && s <= 9) ? 1 : 0; else { int sum = 0; for (int i = least + 1; i <= 8; i++) sum += combination(i, n - 1, s - i); return sum; } }; int main() { while (true) { int n, s; cin >> n; cin >> s; if (n == 0 && s == 0) break; else cout << combination(-1, n, s) << endl; } return 0; }
[["-", 75, 76, 0, 9, 0, 7, 15, 16, 12, 13], ["+", 75, 76, 0, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 11, 12, 2, 3, 4, 0, 16, 12, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 22], ["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13]]
1
143
6
#include <cstdio> #include <iostream> using namespace std; int count; int n, s; void find_dps(int sum, int now, int add_count) { // printf("%d %d : %d %d\n",sum,s,add_count,n); if (now > 9 || add_count > n || sum > s) { return; } if (sum == s && add_count == n) { count++; return; } find_dps(sum + now, now + 1, add_count + 1); find_dps(sum, now + 1, add_count); } int main(int argc, char const *argv[]) { while (true) { cin >> n >> s; if (n == 0 && s == 0) break; count = 0; find_dps(0, 0, 0); cout << count << endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int count; int n, s; void find_dps(int sum, int now, int add_count) { // printf("%d %d : %d %d\n",sum,s,add_count,n); if (now > 10 || add_count > n || sum > s) { return; } if (sum == s && add_count == n) { // printf("now=%d\n", now); count++; return; } find_dps(sum + now, now + 1, add_count + 1); find_dps(sum, now + 1, add_count); } int main(int argc, char const *argv[]) { while (true) { cin >> n >> s; if (n == 0 && s == 0) break; count = 0; find_dps(0, 0, 0); cout << count << endl; } return 0; }
[["-", 15, 339, 51, 16, 31, 16, 31, 16, 12, 13], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 12, 13]]
1
153
2
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define all(c) ((c).begin()), ((c).end()) #define debug(c) cerr << "> " << #c << " = " << (c) << endl; #define iter(c) __typeof((c).begin()) #define present(c, e) ((c).find((e)) != (c).end()) #define cpresent(c, e) (find(all(c), (e)) != (c).end()) #define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++) #define mp make_pair #define fst first #define snd second #define pb push_back const double EPS = 1e-10; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef complex<double> P; int go(int p, int n, int s) { if (n == 0 && s == 0) return 1; if (s <= 0) return 0; int res = 0; REP(i, p + 1, 9) res += go(i, n - 1, s - i); return res; } int main() { for (int n, s; cin >> n >> s, (n | s) != 0;) { cout << go(-1, n, s) << endl; } return 0; }
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define all(c) ((c).begin()), ((c).end()) #define debug(c) cerr << "> " << #c << " = " << (c) << endl; #define iter(c) __typeof((c).begin()) #define present(c, e) ((c).find((e)) != (c).end()) #define cpresent(c, e) (find(all(c), (e)) != (c).end()) #define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++) #define mp make_pair #define fst first #define snd second #define pb push_back const double EPS = 1e-10; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef complex<double> P; int go(int p, int n, int s) { if (n == 0 && s == 0) return 1; if (s < 0) return 0; int res = 0; REP(i, p + 1, 9) res += go(i, n - 1, s - i); return res; } int main() { for (int n, s; cin >> n >> s, (n | s) != 0;) { cout << go(-1, n, s) << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
257
2
#include <iostream> using namespace std; /** Application main entry point. */ int main(int argc, char *argv[]) { int table[11][50] = {}; for (int i = 0; i < 0x800; ++i) /* 0x800: (10000000000)_2 (10 zeros) */ { int sum = 0; int ctr = 0; int cur = -1; while (true) { int __tmp = i >> ++cur; if (!__tmp) break; if (__tmp & 1) { sum += cur; ++ctr; } } table[ctr][sum]++; } while (true) { int n, s; cin >> n >> s; if (n == 0 && s == 0) break; cout << (n >= 0 && n <= 10 && s >= 0 && s <= 45 ? table[n][s] : 0) << endl; } return (0); }
#include <iostream> using namespace std; /** Application main entry point. */ int main(int argc, char *argv[]) { int table[11][50] = {}; for (int i = 0; i < 0x400; ++i) /* 0x400: (10000000000)_2 (10 zeros) */ { int sum = 0; int ctr = 0; int cur = -1; while (true) { int __tmp = i >> ++cur; if (!__tmp) break; if (__tmp & 1) { sum += cur; ++ctr; } } table[ctr][sum]++; } while (true) { int n, s; cin >> n >> s; if (n == 0 && s == 0) break; cout << (n >= 0 && n <= 10 && s >= 0 && s < 50 ? table[n][s] : 0) << endl; } return (0); }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 12, 23, 0, 41, 15, 16, 12, 16, 17, 19], ["-", 12, 23, 0, 41, 15, 16, 12, 16, 12, 13], ["+", 12, 23, 0, 41, 15, 16, 12, 16, 17, 18], ["+", 12, 23, 0, 41, 15, 16, 12, 16, 12, 13]]
1
176
6
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define all(c) (c).begin(), (c).end() #define pb push_back #define mp make_pair #define EXIST(v, i) (find(all(v), i) != (v).end()) #define ERASE(v, i) (v).erase(remove(all(v), i), (v).end()) #define INDEX(v, i) (find(all(v), i) - (v).begin()) #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define debug(x) cerr << #x << " = " << (x) << endl; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const int INF = 100000000; const double PI = 3.14159265358979323846; const double EPS = 1e-10; int main() { for (int n, s; cin >> n >> s && n && s;) { int ret = 0; for (int i = 0; i < (1 << 10); i++) { int sum = 0; if (__builtin_popcount(i) != n) continue; for (int j = 0; j < 10; j++) { if ((1 << j) & i) sum += j; } if (sum == s) ret++; } cout << ret << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define all(c) (c).begin(), (c).end() #define pb push_back #define mp make_pair #define EXIST(v, i) (find(all(v), i) != (v).end()) #define ERASE(v, i) (v).erase(remove(all(v), i), (v).end()) #define INDEX(v, i) (find(all(v), i) - (v).begin()) #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define debug(x) cerr << #x << " = " << (x) << endl; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const int INF = 100000000; const double PI = 3.14159265358979323846; const double EPS = 1e-10; int main() { for (int n, s; cin >> n >> s && (n || s);) { int ret = 0; for (int i = 0; i < (1 << 10); i++) { int sum = 0; if (__builtin_popcount(i) != n) continue; for (int j = 0; j < 10; j++) { if ((1 << j) & i) sum += j; } if (sum == s) ret++; } cout << ret << endl; } return 0; }
[["+", 8, 9, 0, 7, 15, 16, 12, 23, 0, 24], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 98], ["+", 0, 7, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 8, 9, 0, 7, 15, 16, 12, 23, 0, 25]]
1
290
4
#include <iostream> using namespace std; int bitnum(int n) { n = (n & 0x55555555) + ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f); n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff); return (n & 0x0000ffff) + ((n >> 16) & 0x0000ffff); } int main() { int n, s; while (cin >> n >> s, n && s) { int num = 0; for (int i = 0; i < 1 << 10; i++) { if (bitnum(i) != n) continue; int sum = 0; for (int j = 0; j < 10; j++) if ((i >> j) & 1) sum += j; if (sum == s) num++; } cout << num << endl; } return 0; }
#include <iostream> using namespace std; int bitnum(int n) { n = (n & 0x55555555) + ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f); n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff); return (n & 0x0000ffff) + ((n >> 16) & 0x0000ffff); } int main() { int n, s; while (cin >> n >> s, n || s) { int num = 0; for (int i = 0; i < 1 << 10; i++) { if (bitnum(i) != n) continue; int sum = 0; for (int j = 0; j < 10; j++) if ((i >> j) & 1) sum += j; if (sum == s) num++; } cout << num << endl; } return 0; }
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
1
213
2
#include <iostream> using namespace std; int n, s; int countAns(int sum, int pos, int last) { int ans = 0; if (pos > n) { return 0; } else if (pos == n && sum == s) { return 1; } else if (sum >= s) { return 0; } for (int i = last + 1; i < 10; i++) { ans += countAns(sum + i, pos + 1, i); } return ans; } int main() { while (cin >> n >> s) { if (n == 0 && s == 0) { break; } cout << countAns(0, 0, -1) << endl; } return 0; }
#include <iostream> using namespace std; int n, s; int countAns(int sum, int pos, int last) { int ans = 0; if (pos > n) { return 0; } else if (pos == n && sum == s) { return 1; } else if (sum > s) { return 0; } for (int i = last + 1; i < 10; i++) { ans += countAns(sum + i, pos + 1, i); } return ans; } int main() { while (cin >> n >> s) { if (n == 0 && s == 0) { break; } cout << countAns(0, 0, -1) << endl; } return 0; }
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 47]]
1
151
2
#include <iostream> using namespace std; int solve(int n, int s, int k); int main() { int n, s; while (cin >> n >> s, n || s) { int ans = 0; for (int i = 0; i < 10; i++) { if (s >= i) ans += solve(n - 1, s - i, i); } cout << ans << endl; } return 0; } int solve(int n, int s, int k) { int ans = 0; if (n == 0 && s == 0) return 1; else if (n > 0) { for (int i = k + 1; k < 10; i++) { if (s >= i) ans += solve(n - 1, s - i, i); else break; } } return ans; }
#include <iostream> using namespace std; int solve(int n, int s, int k); int main() { int n, s; while (cin >> n >> s, n || s) { int ans = 0; for (int i = 0; i < 10; i++) { if (s >= i) ans += solve(n - 1, s - i, i); } cout << ans << endl; } return 0; } int solve(int n, int s, int k) { int ans = 0; if (n == 0 && s == 0) return 1; else if (n > 0) { for (int i = k + 1; i < 10; i++) { if (s >= i) ans += solve(n - 1, s - i, i); else break; } } return ans; }
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 31, 22]]
1
181
2
#include <iostream> using namespace std; int solver(int cnt, int s, int d) { if (d == 0) return (s == 0) ? 1 : 0; int sum = 0; for (int i = cnt + 1; i <= 9; ++i) { sum += solver(i, s - i, d - 1); } return sum; } int main() { int n, s; while (cin >> n >> s, n != 0 && s != 0) { cout << solver(-1, s, n) << endl; } return 0; }
#include <iostream> using namespace std; int solver(int cnt, int s, int d) { if (d == 0) return (s == 0) ? 1 : 0; int sum = 0; for (int i = cnt + 1; i <= 9; ++i) { sum += solver(i, s - i, d - 1); } return sum; } int main() { int n, s; while (cin >> n >> s, n != 0 || s != 0) { cout << solver(-1, s, n) << endl; } return 0; }
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
1
123
2
#include <iostream> using namespace std; int saiki(int n, int s, int i, int *result) { if (s <= 0) { if (n == 0) { *result += 1; } } else { for (int j = i; j < 10; j++) { saiki(n - j, s - 1, j + 1, result); } } } int main() { int n, s; int result; cin >> n >> s; while (n || s) { result = 0; saiki(n, s, 0, &result); cout << result << endl; cin >> n >> s; } return 0; }
#include <iostream> using namespace std; int saiki(int n, int s, int i, int *result) { if (n <= 0) { if (s == 0) { *result += 1; } } else { for (int j = i; j < 10; j++) { saiki(n - 1, s - j, j + 1, result); } } } int main() { int n, s; int result; cin >> n >> s; while (n || s) { result = 0; saiki(n, s, 0, &result); cout << result << endl; cin >> n >> s; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 64, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22]]
1
140
8
// AOJ Problem0030 #include <iostream> #include <vector> using namespace std; int ans; void solve( int n, int s, int m, int sum, int max) { // n:何個か s:目的値 m:何回目か sum:現在の合計 max:最大の足した数 if (m > n || sum > s) { return; } else if (n == m && sum == s) { ans++; return; } else { for (int i = max + 1; i <= s; i++) { solve(n, s, m + 1, sum + i, i); } } } int main() { int n, s; vector<int> dataN; vector<int> dataS; for (;;) { cin >> n; cin >> s; if (n == 0 && s == 0) { break; } dataN.push_back(n); dataS.push_back(s); } for (int j = 0; j < dataN.size(); j++) { ans = 0; for (int i = 0; i <= s; i++) { solve(dataN[j], dataS[j], 1, i, i); } cout << ans << endl; } return 0; }
// AOJ Problem0030 #include <iostream> #include <vector> using namespace std; int ans; void solve( int n, int s, int m, int sum, int max) { // n:何個か s:目的値 m:何回目か sum:現在の合計 max:最大の足した数 if (m > n || sum > s) { return; } else if (n == m && sum == s) { ans++; return; } else { for (int i = max + 1; i <= 9; i++) { solve(n, s, m + 1, sum + i, i); } } } int main() { int n, s; vector<int> dataN; vector<int> dataS; for (;;) { cin >> n; cin >> s; if (n == 0 && s == 0) { break; } dataN.push_back(n); dataS.push_back(s); } for (int j = 0; j < dataN.size(); j++) { ans = 0; for (int i = 0; i <= 9; i++) { solve(dataN[j], dataS[j], 1, i, i); } cout << ans << endl; } return 0; }
[["-", 75, 76, 0, 9, 0, 7, 15, 16, 12, 22], ["+", 75, 76, 0, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
1
237
4
#include <iostream> using namespace std; int ans; int sum; void dfs(int i, int n, int s) { if (n == 0) { if (sum == s) { ans++; } return; } if (i == 10) return; dfs(i + 1, n, s); dfs(i + 1, n - 1, s + i); } int main(void) { int n; while (cin >> n >> sum, n != 0 && sum != 0) { ans = 0; dfs(0, n, 0); cout << ans << endl; } return (0); }
#include <iostream> using namespace std; int ans; int sum; void dfs(int i, int n, int s) { if (n == 0) { if (sum == s) { ans++; } return; } if (i == 10) return; dfs(i + 1, n, s); dfs(i + 1, n - 1, s + i); } int main(void) { int n; while (cin >> n >> sum, n != 0 || sum != 0) { ans = 0; dfs(0, n, 0); cout << ans << endl; } return (0); }
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
1
133
2
#include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int ans; int n; int s; void count_ans(int k, int C, int j) { if (k == n) { if (C == s) { ans++; } } else { for (int i = j + 1; i < 10; i++) { count_ans(k + 1, C + i, i); } } } int main() { while (cin >> n >> s, (n != 0) && (s != 0)) { ans = 0; count_ans(0, 0, -1); cout << ans << endl; } }
#include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int ans; int n; int s; void count_ans(int k, int C, int j) { if (k == n) { if (C == s) { ans++; } } else { for (int i = j + 1; i < 10; i++) { count_ans(k + 1, C + i, i); } } } int main() { while (cin >> n >> s, (n != 0) || (s != 0)) { ans = 0; count_ans(0, 0, -1); cout << ans << endl; } }
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
1
135
2
#include <stdio.h> #include <string.h> int n; int s; int ans; int sum; bool vis[12]; void init(); void DFS(int source, int k); int main() { while (scanf("%d %d", &n, &s) == 2) { if (n == 0 || s == 0) break; init(); DFS(0, 0); printf("%d\n", ans); } return 0; } void init() { memset(vis, false, sizeof(vis)); ans = 0; sum = 0; } void DFS(int source, int k) { if (source == n) { if (sum == s) { ans++; } return; } for (int i = k; i <= 9; i++) { if (vis[i] == false) { vis[i] = true; sum += i; DFS(source + 1, i); vis[i] = false; sum -= i; } } }
#include <stdio.h> #include <string.h> int n; int s; int ans; int sum; bool vis[12]; void init(); void DFS(int source, int k); int main() { while (scanf("%d %d", &n, &s) == 2) { if (n == 0 && s == 0) break; init(); DFS(0, 0); printf("%d\n", ans); } return 0; } void init() { memset(vis, false, sizeof(vis)); ans = 0; sum = 0; } void DFS(int source, int k) { if (source == n) { if (sum == s) { ans++; } return; } for (int i = k; i <= 9; i++) { if (vis[i] == false) { vis[i] = true; sum += i; DFS(source + 1, i); vis[i] = false; sum -= i; } } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98]]
1
214
2
#include <stdio.h> #include <string.h> int n; int s; int ans; int sum; bool vis[12]; void init(); void DFS(int source, int k); int main() { while (scanf("%d %d", &n, &s) == 2 && (n && s)) { init(); DFS(0, 0); printf("%d\n", ans); } return 0; } void init() { memset(vis, false, sizeof(vis)); ans = 0; sum = 0; } void DFS(int source, int k) { if (source == n) { if (sum == s) { ans++; } return; } for (int i = k; i <= 9; i++) { if (vis[i] == false) { vis[i] = true; sum += i; DFS(source + 1, i); vis[i] = false; sum -= i; } } }
#include <stdio.h> #include <string.h> int n; int s; int ans; int sum; bool vis[12]; void init(); void DFS(int source, int k); int main() { while (scanf("%d %d", &n, &s) == 2 && (n || s)) { init(); DFS(0, 0); printf("%d\n", ans); } return 0; } void init() { memset(vis, false, sizeof(vis)); ans = 0; sum = 0; } void DFS(int source, int k) { if (source == n) { if (sum == s) { ans++; } return; } for (int i = k; i <= 9; i++) { if (vis[i] == false) { vis[i] = true; sum += i; DFS(source + 1, i); vis[i] = false; sum -= i; } } }
[["-", 15, 339, 51, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 106]]
1
208
2
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; const int INF = 1 << 29; typedef long long ll; typedef pair<int, int> PI; int n, s, t, res; void dfs(int n, int t, int sum) { if (n == 0 && sum == s) { res++; return; } if (sum > s || n <= 0 || t > s - sum) return; for (int i = t + 1; i <= 9; ++i) { dfs(n - 1, i, sum + i - 1); } } int main(void) { while (cin >> n >> s, n | s) { if (n == 0 && s == 0) break; res = 0; int ans; dfs(n, 0, 0); cout << res << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; const int INF = 1 << 29; typedef long long ll; typedef pair<int, int> PI; int n, s, t, res; void dfs(int n, int t, int sum) { if (n == 0 && sum == s) { res++; return; } if (sum > s || n <= 0 || t > s - sum) return; for (int i = t + 1; i <= 10; ++i) { dfs(n - 1, i, sum + i - 1); } } int main(void) { while (cin >> n >> s, n | s) { if (n == 0 && s == 0) break; res = 0; int ans; dfs(n, 0, 0); cout << res << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
1
223
2
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; inline int to_int(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string to_str(T x) { ostringstream sout; sout << x; return sout.str(); } typedef long long ll; int num, sum; // now: 現在の数 cnt: 今なん回目? add:何回足した? int judge(int now, int cnt, int add) { if (add == num) { if (now == sum) return 1; else return 0; } else if (cnt > 10) { return 0; } else { return judge(now + cnt, cnt + 1, add + 1) + judge(now, cnt + 1, add); } } int main() { while (cin >> num >> sum) { if (num == 0 && sum == 0) break; cout << judge(0, 0, 0) << endl; } }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; inline int to_int(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string to_str(T x) { ostringstream sout; sout << x; return sout.str(); } typedef long long ll; int num, sum; // now: 現在の数 cnt: 今なん回目? add:何回足した? int judge(int now, int cnt, int add) { if (add == num) { if (now == sum) return 1; else return 0; } else if (cnt > 9) { return 0; } else { return judge(now + cnt, cnt + 1, add + 1) + judge(now, cnt + 1, add); } } int main() { while (cin >> num >> sum) { if (num == 0 && sum == 0) break; cout << judge(0, 0, 0) << endl; } }
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13]]
1
222
2
#include <iostream> #include <vector> using namespace std; void func(int start, int num, int current); int s, res; int main(void) { int n; cin >> n; cin >> s; while (n != 0 && s != 0) { res = 0; func(0, n, 0); cout << res << endl; cin >> n; cin >> s; } } void func(int start, int num, int current) { int temp = 0; for (int i = start; i < 10; i++) { if (current + i <= s) temp = current + i; else break; if (num != 1) func(i + 1, num - 1, temp); else if (temp == s) { res++; } temp = 0; } }
#include <iostream> #include <vector> using namespace std; void func(int start, int num, int current); int s, res; int main(void) { int n; cin >> n; cin >> s; while (n != 0 || s != 0) { res = 0; func(0, n, 0); cout << res << endl; cin >> n; cin >> s; } return 0; } void func(int start, int num, int current) { int temp = 0; for (int i = start; i < 10; i++) { if (current + i <= s) temp = current + i; else break; if (num != 1) func(i + 1, num - 1, temp); else if (temp == s) { res++; } temp = 0; } }
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 106], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
1
170
5
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n, s; int Sum_of_Integers(int i, int sum, int v); int main() { while (1) { cin >> n >> s; if (!n && !s) break; cout << Sum_of_Integers(0, 0, -1) << endl; } } int Sum_of_Integers(int i, int sum, int v) { int ret = 0; if (i > n || sum > s) return 0; // あふれたとき if (i == n && sum == s) return 1; for (int j = 0; j <= 9 - sum; j++) { if (v < j) ret += Sum_of_Integers(i + 1, sum + j, j); } return ret; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n, s; int Sum_of_Integers(int i, int sum, int v); int main() { while (1) { cin >> n >> s; if (!n && !s) break; cout << Sum_of_Integers(0, 0, -1) << endl; } } int Sum_of_Integers(int i, int sum, int v) { int ret = 0; if (i > n || sum > s) return 0; // あふれたとき if (i == n && sum == s) return 1; for (int j = 0; j <= 9; j++) { if (v < j) ret += Sum_of_Integers(i + 1, sum + j, j); } return ret; }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22]]
1
159
2
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <set> #include <stack> #include <vector> using namespace std; int dfs(int n, int s, int k) { if (n == 0 && s == 0) { return 1; } if (n == 0) return 0; if (s <= 0) return 0; if (k > 9 || k > s) return 0; int res1 = dfs(n - 1, s - k, k + 1); int res2 = dfs(n, s, k + 1); return res1 + res2; } bool solve() { int n, s; while (1) { cin >> n >> s; if (n == 0 && s == 0) break; int res = dfs(n, s, 0); cout << res << endl; } return true; } int main() { cout.setf(ios::fixed); cout.precision(10); solve(); return 0; }
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <set> #include <stack> #include <vector> using namespace std; int dfs(int n, int s, int k) { if (n == 0 && s == 0) { return 1; } if (n == 0) return 0; if (s < 0) return 0; //ココ if (k > 9 || k > s) return 0; int res1 = dfs(n - 1, s - k, k + 1); int res2 = dfs(n, s, k + 1); return res1 + res2; } bool solve() { int n, s; while (1) { cin >> n >> s; if (n == 0 && s == 0) break; int res = dfs(n, s, 0); cout << res << endl; } return true; } int main() { cout.setf(ios::fixed); cout.precision(10); solve(); return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
212
2
#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int combi(int n, int s, vector<int> usedNum) { int combiCount = 0; int tmp; bool usedFlag; n--; for (int i = 0; i <= 9; i++) { usedFlag = false; for (int j = 0; j < usedNum.size(); j++) { if (usedNum[j] == i) usedFlag = true; } if (usedFlag) { continue; } tmp = s; tmp -= i; if (n != 0) { usedNum.push_back(i); combiCount += combi(n, tmp, usedNum); } else if (n == 0 && tmp == 0) { usedNum.pop_back(); return ++combiCount; } } usedNum.pop_back(); return combiCount; } int main() { int n, s; int combiCount = 0; vector<int> usedNum; while (cin >> n >> s && n != 0 && s != 0) { combiCount = combi(n, s, usedNum); cout << combiCount << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int combi(int n, int s, vector<int> usedNum) { int combiCount = 0; int tmp; bool usedFlag; n--; for (int i = 0; i <= 9; i++) { usedFlag = false; for (int j = 0; j < usedNum.size(); j++) { if (usedNum[j] == i) usedFlag = true; } if (usedFlag) { continue; } tmp = s; tmp -= i; if (n != 0) { usedNum.push_back(i); combiCount += combi(n, tmp, usedNum); } else if (n == 0 && tmp == 0) { usedNum.pop_back(); return ++combiCount; } } usedNum.pop_back(); return combiCount; } int main() { int n, s; int combiCount = 0; vector<int> usedNum; while (cin >> n >> s && (n != 0 || s != 0)) { combiCount = combi(n, s, usedNum); cout << combiCount << endl; } return 0; }
[["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 24], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 25]]
1
244
18
#include <iostream> using namespace std; int n, s; int cou(int i, int cn, int cs) { if (cs > s || cn > n) return 0; if ((cn == n || cn == n - 1) && cs == s) return 1; int ans = 0; for (; i < 10; i++) ans += cou(i, cn + 1, cs + i); return ans; } int main(void) { while (cin >> n >> s, n | s) { cout << cou(1, 0, 0) << endl; } return 0; }
#include <iostream> using namespace std; int n, s; int cou(int i, int cn, int cs) { if (cs > s || cn > n) return 0; if ((cn == n || cn == n - 1) && cs == s) return 1; int ans = 0; i++; for (; i < 10; i++) ans += cou(i, cn + 1, cs + i); return ans; } int main(void) { while (cin >> n >> s, n | s) { cout << cou(0, 0, 0) << endl; } return 0; }
[["+", 0, 14, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13]]
1
129
5
#include <iostream> using namespace std; int n, s; int recursion(int sum, int num, int cnt) { if (sum > s || cnt > n) return 0; if (cnt == n && sum == s) return 1; if (num > s) return 0; int hoge = 0; hoge += recursion(sum + num, num + 1, cnt + 1); hoge += recursion(sum, num + 1, cnt); return hoge; } int main() { while (cin >> n >> s, n || s) { cout << recursion(0, 0, 0) << endl; } }
#include <iostream> using namespace std; int n, s; int recursion(int sum, int num, int cnt) { if (sum > s || cnt > n) return 0; if (cnt == n && sum == s) return 1; if (num > 9) return 0; int hoge = 0; hoge += recursion(sum + num, num + 1, cnt + 1); hoge += recursion(sum, num + 1, cnt); return hoge; } int main() { while (cin >> n >> s, n || s) { cout << recursion(0, 0, 0) << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
131
2
#include <iostream> #include <queue> using namespace std; int res; const int d[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; void dfs(int now, int idx, int n, int sum, int s) { if (now == n) { if (sum == s) { res++; } } if (idx < 10) { dfs(now, idx + 1, n, sum, s); dfs(now + 1, idx + 1, n, sum + d[idx], s); } } int main() { int n, s; queue<int> que; while (cin >> n >> s, n || s) { res = 0; dfs(0, 0, n, 0, s); que.push(res); } while (que.size()) { cout << que.front() << endl; que.pop(); } return 0; }
#include <iostream> #include <queue> using namespace std; int res; const int d[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; void dfs(int now, int idx, int n, int sum, int s) { if (now == n) { if (sum == s) { res++; return; } } if (idx < 10) { dfs(now, idx + 1, n, sum, s); dfs(now + 1, idx + 1, n, sum + d[idx], s); } } int main() { int n, s; queue<int> que; while (cin >> n >> s, n || s) { res = 0; dfs(0, 0, n, 0, s); que.push(res); } while (que.size()) { cout << que.front() << endl; que.pop(); } return 0; }
[["+", 64, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 64, 9, 0, 57, 64, 9, 0, 37, 0, 35]]
1
208
2
#include <iostream> using namespace std; int count(int m, int n, int s) { if (n == 0) { if (s == 0) return 1; return 0; } int c = 0; for (int i = m; i <= 9; i++) { cout << endl; c += count(i + 1, n - 1, s - i); } return c; } int main(void) { int n, s; while (true) { cin >> n >> s; if (n == 0 && s == 0) break; cout << count(0, n, s) << endl; } return 0; }
#include <iostream> using namespace std; int count(int m, int n, int s) { if (n == 0) { if (s == 0) return 1; return 0; } int c = 0; for (int i = m; i <= 9; i++) { c += count(i + 1, n - 1, s - i); } return c; } int main(void) { int n, s; while (true) { cin >> n >> s; if (n == 0 && s == 0) break; cout << count(0, n, s) << endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
1
137
4
#!/usr/bin/ruby loop do n, s = gets.split.map(&:to_i) break if n == 0 && s == 0 [*0..9].combination(n).count{|x| x.inject(:+) == s } end
#!/usr/bin/ruby loop do n, s = gets.split.map(&:to_i) break if n == 0 && s == 0 puts [*0..9].combination(n).count{|x| x.inject(:+) == s } end
[["+", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22]]
4
52
1
#!/usr/bin/env python # -*- coding: utf-8 -*- import itertools S = [] N = [] while True: n,s = map(int,input().split(" ")) if s == 0 and n == 0: break else: N.append(n) S.append(s) for i in range(0,len(S)): sumMap = list(map(sum,list(itertools.combinations(range(0,S[i]+1),N[i])))) print(sum([1 for j in range(0,len(sumMap)) if sumMap[j] == S[i]]))
#!/usr/bin/env python # -*- coding: utf-8 -*- import itertools S = [] N = [] while True: n,s = map(int,input().split(" ")) if s == 0 and n == 0: break else: N.append(n) S.append(s) for i in range(0,len(S)): sumMap = list(map(sum,list(itertools.combinations(range(0,10),N[i])))) print(sum([1 for j in range(0,len(sumMap)) if sumMap[j] == S[i]]))
[["-", 0, 652, 3, 4, 0, 657, 31, 206, 51, 22], ["-", 0, 652, 3, 4, 0, 657, 31, 206, 0, 70], ["-", 0, 652, 3, 4, 0, 657, 31, 206, 206, 22], ["-", 0, 652, 3, 4, 0, 657, 31, 206, 0, 73], ["-", 3, 4, 0, 652, 3, 4, 0, 657, 17, 72], ["-", 3, 4, 0, 652, 3, 4, 0, 657, 12, 612], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 612]]
5
136
7
import sys f = sys.stdin while True: n, s = map(int, f.readline().split()) if n == 0: break print(sum(1 for nums in itertools.combinations([i for i in range(10)], n) if sum(nums) == s))
import sys f = sys.stdin import itertools while True: n, s = map(int, f.readline().split()) if n == 0: break print(sum(1 for nums in itertools.combinations([i for i in range(10)], n) if sum(nums) == s))
[["+", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["+", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22]]
5
68
2
def move(move_count, current, flag): for i in range(move_count): n_lis.append(num_lis[current+i]) if flag == n: calculate() del n_lis[-1] else: move(move_count, current+i+1, flag+1) move_count -= 1 del n_lis[-1] def calculate(): global count if sum(n_lis) == s: count += 1 while True: n, s = list(map(int, input().split())) if n == 0 and s == 0: break num_lis = [0,1,2,3,4,5,6,7,8,9] n_lis = [] count = 0 move(8,0,1) print(count)
def move(move_count, current, flag): for i in range(move_count): n_lis.append(num_lis[current+i]) if flag == n: calculate() del n_lis[-1] else: move(move_count, current+i+1, flag+1) move_count -= 1 del n_lis[-1] def calculate(): global count if sum(n_lis) == s: count += 1 while True: n, s = list(map(int, input().split())) if n == 0 and s == 0: break num_lis = [0,1,2,3,4,5,6,7,8,9] n_lis = [] count = 0 move(10-n+1,0,1) print(count)
[["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 612], ["+", 0, 652, 3, 4, 0, 657, 31, 657, 31, 612], ["+", 0, 652, 3, 4, 0, 657, 31, 657, 17, 33], ["+", 0, 652, 3, 4, 0, 657, 31, 657, 12, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
160
9
a = [0,1,2,3,4,5,6,7,8,9] wa_lis = [] num = 0 def wa(n,k,m): global num if n == 9 and m == 0 and k == 0: num += 1 if n == 10: return return wa(n + 1,k - a[n],m - 1) or wa(n+1,k,m) while True: n,s = map(int,input().split()) if [n,s] == [0,0]: break wa(0,s,n) print(num) num = 0
a = [0,1,2,3,4,5,6,7,8,9] wa_lis = [] num = 0 def wa(n,k,m): global num if n == 10 and m == 0 and k == 0: num += 1 if n == 10: return return wa(n + 1,k - a[n],m - 1) or wa(n+1,k,m) while True: n,s = map(int,input().split()) if [n,s] == [0,0]: break wa(0,s,n) print(num) num = 0
[["-", 0, 57, 15, 679, 31, 679, 31, 666, 0, 612], ["+", 0, 57, 15, 679, 31, 679, 31, 666, 0, 612]]
5
141
2
#include <bits/stdc++.h> using namespace std; int main() { int w; while (cin >> w) { vector<int> v; for (int i = 0; i <= 8; i++) { if (w >> i & 1) { v.push_back(1 << i); } } for (int i = 0; i < (int)v.size(); i++) { if (i > 0) cout << " "; cout << v[i]; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int w; while (cin >> w) { vector<int> v; for (int i = 0; i <= 9; i++) { if (w >> i & 1) { v.push_back(1 << i); } } for (int i = 0; i < (int)v.size(); i++) { if (i > 0) cout << " "; cout << v[i]; } cout << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
1
113
2
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n; int square[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; vector<int> num; while (cin >> n) { if (n == 0) break; for (int i = 9; i >= 0; i--) { if (n >= square[i]) { num.push_back(i); n -= square[i]; } } for (int i = num.size() - 1; i >= 0; i--) { cout << square[num[i]]; if (i = 0) cout << endl; else cout << " "; } num.clear(); } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n; int square[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; vector<int> num; while (cin >> n) { if (n == 0) break; for (int i = 9; i >= 0; i--) { if (n >= square[i]) { num.push_back(i); n -= square[i]; } } for (int i = num.size() - 1; i >= 0; i--) { cout << square[num[i]]; if (i == 0) cout << endl; else cout << " "; } num.clear(); } }
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
164
2
#include <iostream> #include <queue> using namespace std; int main() { int w, we[9] = {1, 2, 4, 8, 16, 32, 64, 128, 256}, i; queue<int> k; while (cin >> w) { while (w != 0) { k.push(w % 2); w = w / 2; } i = 0; while (k.size()) { if (k.front() == 1 && k.size() >= 2) cout << we[i] << " "; else if (k.front() == 1) cout << we[i] << endl; k.pop(); i++; } } return 0; }
#include <iostream> #include <queue> using namespace std; int main() { int w, we[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}, i; queue<int> k; while (cin >> w) { while (w != 0) { k.push(w % 2); w = w / 2; } i = 0; while (k.size()) { if (k.front() == 1 && k.size() >= 2) cout << we[i] << " "; else if (k.front() == 1) cout << we[i] << endl; k.pop(); i++; } } return 0; }
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 21], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 13]]
1
156
4
#include <algorithm> #include <math.h> #include <stdio.h> using namespace std; class STACK { public: STACK() { index = 0; } void push(int data) { array[index++] = data; } int pop() { index--; return array[index]; } bool isEmpty() { return index == 0; } int getIndex() { return index; } private: int array[10]; int index; }; int main() { int w; STACK stack; while (scanf("%d", &w) != EOF) { for (int i = 256; i >= 1; i /= 2) { if (w >= i) { stack.push(i); w -= i; } } while (!stack.isEmpty()) { if (stack.getIndex() == 1) { printf("%d\n", stack.pop()); } else { printf("%d ", stack.pop()); } } } return 0; }
#include <algorithm> #include <math.h> #include <stdio.h> using namespace std; class STACK { public: STACK() { index = 0; } void push(int data) { array[index++] = data; } int pop() { index--; return array[index]; } bool isEmpty() { return index == 0; } int getIndex() { return index; } private: int array[10]; int index; }; int main() { int w; STACK stack; while (scanf("%d", &w) != EOF) { for (int i = 512; i >= 1; i /= 2) { if (w >= i) { stack.push(i); w -= i; } } while (!stack.isEmpty()) { if (stack.getIndex() == 1) { printf("%d\n", stack.pop()); } else { printf("%d ", stack.pop()); } } } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
208
2
#include <algorithm> #include <cctype> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; int arr[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int main() { int N; while (cin >> N) { int count = 0; int num[10] = {0}; while (N) { num[count++] = N % 2; N /= 2; } for (int i = 0; i < count - 1; i++) { if (num[i]) cout << arr[num[i]] << " "; } if (num[count - 1]) cout << arr[num[count - 1]] << endl; else cout << endl; } // while(1); return 0; }
#include <algorithm> #include <cctype> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; int arr[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int main() { int N; while (cin >> N) { int count = 0; int num[10] = {0}; while (N) { num[count++] = N % 2; N /= 2; } for (int i = 0; i < count - 1; i++) { if (num[i]) cout << arr[i] << " "; } if (num[count - 1]) cout << arr[count - 1] << endl; else cout << endl; } // while(1); return 0; }
[["-", 31, 16, 12, 69, 341, 342, 0, 69, 28, 22], ["-", 12, 69, 341, 342, 0, 69, 341, 342, 0, 70], ["-", 12, 69, 341, 342, 0, 69, 341, 342, 0, 73], ["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 70]]
1
183
6
#include <bits/stdc++.h> using namespace std; int main() { ios ::sync_with_stdio(false); for (int n; cin >> n;) { for (int i = 0; i < 9; i++) if ((n >> i) & 1) { n -= (1 << i); cout << (1 << i) << (n ? ' ' : '\n'); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios ::sync_with_stdio(false); for (int n; cin >> n;) { for (int i = 0; i < 10; i++) if ((n >> i) & 1) { n -= (1 << i); cout << (1 << i) << (n ? ' ' : '\n'); } } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
1
88
2
#include <iostream> using namespace std; int main() { int ln; int weit[] = {1, 2, 4, 8, 16, 32, 64, 128, 256}; bool fl; int n; while (cin >> n) { ln = 0; fl = 0; bool two[20] = {0}; while (n) { two[ln] = n % 2; n /= 2; ln++; } int i; // cout << ln; for (i = 0; i < ln; i++) { // cout << "A" << two[i]; if (two[i] == 1) { if (fl) { cout << " "; } fl = true; cout << weit[i]; } } cout << endl; } return 0; }
#include <iostream> using namespace std; int main() { int ln; int weit[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; bool fl; int n; while (cin >> n) { ln = 0; fl = 0; bool two[20] = {0}; while (n) { two[ln] = n % 2; n /= 2; ln++; } int i; for (i = 0; i < ln; i++) { if (two[i] == 1) { if (fl) { cout << " "; } fl = true; cout << weit[i]; } } cout << endl; } return 0; }
[["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 21], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 13]]
1
155
2
#include <iostream> int main() { auto powor_of_two = [](int n) { int result = 1; for (int i = 0; i < n; i++) { result *= 2; } return result; }; for (int w; std::cin >> w;) { for (int i = 0; i < 10; i++) { int bit = w & 1; if (bit == 1) { std::cout << powor_of_two(i); w >>= 1; if (w != 0) { std::cout << 'a'; } else { std::cout << std::endl; break; } } else { w >>= 1; } } } return 0; }
#include <iostream> int main() { auto powor_of_two = [](int n) { int result = 1; for (int i = 0; i < n; i++) { result *= 2; } return result; }; for (int w; std::cin >> w;) { for (int i = 0; i < 10; i++) { int bit = w & 1; if (bit == 1) { std::cout << powor_of_two(i); w >>= 1; if (w != 0) { std::cout << ' '; } else { std::cout << std::endl; break; } } else { w >>= 1; } } } return 0; }
[["-", 64, 9, 0, 1, 0, 16, 12, 103, 0, 125], ["+", 64, 9, 0, 1, 0, 16, 12, 103, 0, 125]]
1
145
2
#include <iostream> using namespace std; int main() { int N; while (cin >> N) { bool first = true; for (int i = 1; i < N; i <<= 1) { if (N & i) { if (!first) cout << ' '; cout << i; first = false; } } cout << endl; } return 0; }
#include <iostream> using namespace std; int main() { int N; while (cin >> N) { bool first = true; for (int i = 1; i <= N; i <<= 1) { if (N & i) { if (!first) cout << ' '; cout << i; first = false; } } cout << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
79
2
#include <algorithm> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { int p2[10] = {512, 256, 128, 64, 32, 16, 8, 4, 2, 1}, n; vector<int> v; while (cin >> n) { for (int i = 0; i < 10; i++) { if (n >= p2[i]) n -= p2[i], v.push_back(p2[i]); } sort(v.begin(), v.end()); vector<int>::iterator it = v.begin(); for (; it != v.end(); it++) { cout << *it; (it == v.end()) ? cout << endl : cout << " "; } v.clear(); } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { int p2[10] = {512, 256, 128, 64, 32, 16, 8, 4, 2, 1}, n; vector<int> v; while (cin >> n) { for (int i = 0; i < 10; i++) { if (n >= p2[i]) n -= p2[i], v.push_back(p2[i]); } sort(v.begin(), v.end()); vector<int>::iterator it = v.begin(); for (; it != v.end(); it++) { cout << *it; (it + 1 == v.end()) ? cout << endl : cout << " "; } v.clear(); } return 0; }
[["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 72], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 13]]
1
185
2
#include <stdio.h> int main(void) { int n; while (scanf("%d", &n) != EOF) { int i; int flag; flag = 0; for (i = 0; i < 9; i++) { if (((n >> i) & 1) != 0) { if (flag == 0) { printf("%d", 1 << i); } else { printf(" %d", 1 << i); } flag = 1; } } puts(""); } return (0); }
#include <stdio.h> int main(void) { int n; while (scanf("%d", &n) != EOF) { int i; int flag; flag = 0; for (i = 0; i < 20; i++) { if (((n >> i) & 1) != 0) { if (flag == 0) { printf("%d", 1 << i); } else { printf(" %d", 1 << i); } flag = 1; } } puts(""); } return (0); }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
1
117
2
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int main() { int w; while (cin >> w) { set<int> weights; for (int i = 8; 0 <= i; i--) { int weight = pow(2.0, i); if (weight <= w) { w -= weight; weights.insert(weight); } } for (set<int>::iterator it = weights.begin(); it != weights.end();) { cout << *it; if (++it == weights.end()) { cout << endl; } else { cout << ' '; } } } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int main() { int w; while (cin >> w) { set<int> weights; for (int i = 9; 0 <= i; i--) { int weight = pow(2, i); if (weight <= w) { w -= weight; weights.insert(weight); } } for (set<int>::iterator it = weights.begin(); it != weights.end();) { cout << *it; if (++it == weights.end()) { cout << endl; } else { cout << ' '; } } } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 43, 49, 50, 51, 2, 3, 4, 0, 13], ["+", 0, 43, 49, 50, 51, 2, 3, 4, 0, 13]]
1
161
4
// 53 #include <iostream> using namespace std; int main() { for (int n; cin >> n;) { bool out = false; for (int i = 0; i <= 8; i++) { if (n & 1 << i) { if (out) { cout << ' '; } out = true; cout << (1 << i); } } cout << endl; } return 0; }
// 53 #include <iostream> using namespace std; int main() { for (int n; cin >> n;) { bool out = false; for (int i = 0; i <= 9; i++) { if (n & 1 << i) { if (out) { cout << ' '; } out = true; cout << (1 << i); } } cout << endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
1
87
2
// AOJ 0031 #include <iostream> #include <stdio.h> #include <vector> using namespace std; int main() { int data[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int num; while (cin >> num) { int tmp = 0; for (int j = 0; j < 10; j++) { if (num % 2 == 1) { if (tmp == 0) { printf("%d", data[j]); tmp++; } else { printf(" %d", data[j]); } num /= 2; } printf("\n"); } } return 0; }
// AOJ 0031 #include <iostream> #include <stdio.h> #include <vector> using namespace std; int main() { int data[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int num; while (cin >> num) { int tmp = 0; for (int j = 0; j < 10; j++) { if (num % 2 == 1) { if (tmp == 0) { printf("%d", data[j]); tmp++; } else { printf(" %d", data[j]); } } num /= 2; } printf("\n"); } return 0; }
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 52, 8, 9, 0, 7, 8, 9, 0, 46]]
1
139
2
#include <algorithm> #include <cstring> #include <iostream> #include <vector> using namespace std; int main() { vector<int> ar; int g[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int n; while (cin >> n) { for (int i = 9; i >= 0; i--) { if (n >= g[i]) { n -= g[i]; ar.push_back(g[i]); } } for (int i = ar.size() - 1; i >= 0; i--) { if (i != 0) cout << ar[i] << ' '; else cout << ar[i] << endl; } } }
#include <algorithm> #include <cstring> #include <iostream> #include <vector> using namespace std; int main() { vector<int> ar; int g[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int n; while (cin >> n) { for (int i = 9; i >= 0; i--) { if (n >= g[i]) { n -= g[i]; ar.push_back(g[i]); } } for (int i = ar.size() - 1; i >= 0; i--) { if (i != 0) cout << ar[i] << ' '; else cout << ar[i] << endl; } ar.clear(); } }
[["+", 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
155
6
#include <iostream> using namespace std; int main() { int n, b[10], f, i; while (cin >> n) { for (i = 0; i < 9; i++) { b[i] = n % 2; n /= 2; } for (f = 0, n = 1, i = 0; i < 9; i++) { if (b[i] == 1) { if (f == 0) { cout << n; f = 1; } else cout << " " << n; } n *= 2; } cout << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, b[10], f, i; while (cin >> n) { for (i = 0; i < 10; i++) { b[i] = n % 2; n /= 2; } for (f = 0, n = 1, i = 0; i < 10; i++) { if (b[i] == 1) { if (f == 0) { cout << n; f = 1; } else cout << " " << n; } n *= 2; } cout << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
1
130
4
#include <iostream> #include <math.h> using namespace std; int main() { int n; while (cin >> n) { int weight[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (int i = 9; i >= 0; i--) { if (n >= pow(2, i)) { n -= pow(2, i); weight[i] = 1; } } int i; for (i = 0; i < 10; i++) { if (weight[i]) { cout << pow(2, i); break; } } for (; i < 10; i++) { if (weight[i]) { cout << " " << pow(2, i); } } cout << endl; } return 0; }
#include <iostream> #include <math.h> using namespace std; int main() { int n; while (cin >> n) { int weight[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (int i = 9; i >= 0; i--) { if (n >= pow(2, i)) { n -= pow(2, i); weight[i] = 1; } } int i; for (i = 0; i < 10; i++) { if (weight[i]) { cout << pow(2, i); i++; break; } } for (; i < 10; i++) { if (weight[i]) { cout << " " << pow(2, i); } } cout << endl; } return 0; }
[["+", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 27, 17, 29], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
1
176
3
#include <iostream> using namespace std; int main() { int weight[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int n; while (cin >> n, n) { int j = 0; int ans[10]; for (int i = 9; i >= 0; i--) { if (n == 0) break; if (n >= weight[i]) { n -= weight[i]; ans[j++] = weight[i]; } } for (int i = j - 1; i >= 0; i--) { if (i == 0) { cout << endl; break; } cout << ans[i] << ' '; } } }
#include <iostream> using namespace std; int main() { int weight[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int n; while (cin >> n, n) { int j = 0; int ans[10]; for (int i = 9; i >= 0; i--) { if (n == 0) break; if (n >= weight[i]) { n -= weight[i]; ans[j++] = weight[i]; } } for (int i = j - 1; i >= 0; i--) { if (i == 0) { cout << ans[i] << endl; break; } cout << ans[i] << ' '; } } }
[["+", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 70], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 73], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151]]
1
160
5
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main(void) { int h[10], w; vector<int> ans; rep(i, 10) { h[i] = pow(2.0, (double)i); } while (cin >> w) { ans.clear(); for (int i = 9; i >= 0; i--) { if (w <= 1) { ans.push_back(h[0]); break; } else if (h[i] <= w) { ans.push_back(h[i]); w -= h[i]; } } for (int i = (int)ans.size() - 1; i >= 0; i--) { cout << ans[i]; i == 0 ? cout << endl : cout << " "; } } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main(void) { int h[10], w; vector<int> ans; rep(i, 10) { h[i] = pow(2.0, (double)i); } while (cin >> w) { ans.clear(); for (int i = 9; i >= 0; i--) { if (w == 1) { ans.push_back(h[0]); break; } else if (h[i] <= w) { ans.push_back(h[i]); w -= h[i]; } } for (int i = (int)ans.size() - 1; i >= 0; i--) { cout << ans[i]; i == 0 ? cout << endl : cout << " "; } } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
199
2
#include <stdio.h> int main() { int a; int weight[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; while (~scanf("%d", &a)) { bool t[10]; for (int i = 9; i > -1; i--) t[i] = false; for (int i = 9; i > -1; i--) { if (weight[i] <= a) { a -= weight[i]; t[i] = true; } } int i; for (i = 0; i < 10; i++) { if (t[i]) { printf("%d", weight[i]); break; } } for (; i < 10; i++) { if (t[i]) printf(" %d", weight[i]); } printf("\n"); } return 0; }
#include <stdio.h> int main() { int a; int weight[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; while (~scanf("%d", &a)) { bool t[10]; for (int i = 9; i > -1; i--) t[i] = false; for (int i = 9; i > -1; i--) { if (weight[i] <= a) { a -= weight[i]; t[i] = true; } } int i; for (i = 0; i < 10; i++) { if (t[i]) { printf("%d", weight[i]); break; } } for (i++; i < 10; i++) { if (t[i]) printf(" %d", weight[i]); } printf("\n"); } return 0; }
[["+", 0, 52, 8, 9, 0, 7, 10, 27, 28, 22], ["+", 0, 52, 8, 9, 0, 7, 10, 27, 17, 29]]
1
204
2
#include <iostream> using namespace std; int main() { int wigth; cin >> wigth; int i = 1; bool flag = false; while (i <= 512) { if (wigth & i) { if (flag) cout << " "; cout << i; flag = true; } i *= 2; } cout << endl; return 0; }
#include <iostream> using namespace std; int main() { int wigth; while (cin >> wigth) { int i = 1; bool flag = false; while (i <= 512) { if (wigth & i) { if (flag) cout << " "; cout << i; flag = true; } i *= 2; } cout << 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
74
6
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define vci vector<int> #define vcs vector<string> #define pb push_back #define sz size() #define mapii map<int, int> #define mapci map<char, int> #define mapsi map<string, int> #define all(x) x.begin(), x.end() #define minit(a, i) memset(a, i, sizeof(a)); #define for_(i, a, b) for (int i = (int)a; i < (int)b; i++) #define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--) #define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c) #define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) typedef long long ll; const int iINF = 2147483647; const ll lINF = 9223372036854775807; template <class T> inline void dbg(T t) { cout << t << endl; } int main() { int in; while (cin >> in) { bitset<10> b(in); int hit = 0; for_(i, 0, 9) { if (b[i]) { if (hit > 0) cout << " "; cout << pow(2, i); hit++; } } cout << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define vci vector<int> #define vcs vector<string> #define pb push_back #define sz size() #define mapii map<int, int> #define mapci map<char, int> #define mapsi map<string, int> #define all(x) x.begin(), x.end() #define minit(a, i) memset(a, i, sizeof(a)); #define for_(i, a, b) for (int i = (int)a; i < (int)b; i++) #define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--) #define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c) #define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) typedef long long ll; const int iINF = 2147483647; const ll lINF = 9223372036854775807; template <class T> inline void dbg(T t) { cout << t << endl; } int main() { int in; while (cin >> in) { bitset<10> b(in); int hit = 0; for_(i, 0, 10) { if (b[i]) { if (hit > 0) cout << " "; cout << pow(2, i); hit++; } } cout << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
1
243
2
#include <bits/stdc++.h> using namespace std; int main() { for (int n; cin >> n;) { vector<int> ans; for (int bit = 1; bit < n; bit <<= 1) { if (bit & n) ans.emplace_back(bit); } for (unsigned i = 0; i < ans.size(); ++i) { cout << ans[i] << (i + 1 == ans.size() ? "\n" : " "); } } return EXIT_SUCCESS; }
#include <bits/stdc++.h> using namespace std; int main() { for (int n; cin >> n;) { vector<int> ans; for (int bit = 1; bit <= n; bit <<= 1) { if (bit & n) ans.emplace_back(bit); } for (unsigned i = 0; i < ans.size(); ++i) { cout << ans[i] << (i + 1 == ans.size() ? "\n" : " "); } } return EXIT_SUCCESS; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
110
2
while line = gets arr = [] line.to_i.to_s(2).split("").each_with_index do |elm, idx| arr << 2 ** idx if elm == "1" end puts arr.join(" ") end
while line = gets arr = [] line.to_i.to_s(2).split("").reverse.each_with_index do |b, i| arr << 2 ** i if b == "1" end puts arr.join(" ") end
[["+", 0, 89, 8, 170, 0, 652, 486, 652, 735, 22], ["+", 0, 493, 0, 89, 8, 170, 0, 652, 17, 131], ["-", 8, 170, 0, 652, 196, 737, 54, 758, 0, 22], ["+", 8, 170, 0, 652, 196, 737, 54, 758, 0, 22], ["-", 8, 736, 0, 751, 8, 738, 12, 738, 12, 22], ["+", 8, 736, 0, 751, 8, 738, 12, 738, 12, 22], ["-", 196, 737, 8, 736, 0, 751, 15, 738, 31, 22], ["+", 196, 737, 8, 736, 0, 751, 15, 738, 31, 22]]
4
52
10
weight = gets.chomp.to_i ans = Array.new 9.step(0, -1) do |i| if weight >= 2**i ans.push(2**i) weight = weight - 2**i end end puts ans.sort.join(" ")
while weight = gets weight = weight.chomp.to_i ans = Array.new 9.step(0, -1) do |i| if weight >= 2**i ans.push(2**i) weight = weight - 2**i end end puts ans.sort.join(" ") end
[["+", 36, 36, 36, 36, 0, 493, 0, 89, 0, 89], ["+", 0, 493, 0, 89, 8, 170, 0, 662, 31, 22], ["+", 0, 493, 0, 89, 8, 170, 0, 662, 0, 32], ["+", 8, 170, 0, 662, 12, 652, 486, 652, 486, 22], ["+", 36, 36, 0, 493, 0, 89, 8, 170, 0, 444]]
4
59
5
while gets w = $_.to_i a = [] 9.times{|i| unless (c = (1<<i & w)) == 0 then a << c end } puts a.join(" ") end
while gets w = $_.to_i a = [] 10.times{|i| unless (c = (1<<i & w)) == 0 then a << c end } puts a.join(" ") end
[["-", 0, 493, 0, 89, 8, 170, 0, 652, 486, 612], ["+", 0, 493, 0, 89, 8, 170, 0, 652, 486, 612]]
4
48
2
#!/usr/local/bin/ruby a=gets.to_i w=a.to_s(2) rec=Array.new y=w.split("").map(&:to_i).reverse l=y.size (l-1).downto(0){|i| if y[i]==1 rec.unshift(2**i) end } puts rec.join(" ")
#!/usr/local/bin/ruby while line=gets a=line.to_i w=a.to_s(2) rec=Array.new y=w.split("").map(&:to_i).reverse l=y.size (l-1).downto(0){|i| if y[i]==1 rec.unshift(2**i) end } puts rec.join(" ") end
[["-", 36, 36, 36, 36, 0, 493, 0, 662, 31, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 89, 0, 89], ["+", 36, 36, 0, 493, 0, 89, 15, 662, 31, 22], ["+", 0, 493, 0, 89, 8, 170, 0, 662, 31, 22], ["+", 0, 493, 0, 89, 8, 170, 0, 662, 0, 32], ["+", 0, 89, 8, 170, 0, 662, 12, 652, 486, 22], ["+", 36, 36, 0, 493, 0, 89, 8, 170, 0, 444]]
4
81
7
n = gets.to_i a = 1 while a <= n if (a & n) == a print a print" " if a << 1 <= n end a <<= 1 end puts
while gets n = $_.to_i a = 1 while a <= n if (a & n) == a print a print" " if a << 1 <= n end a <<= 1 end puts end
[["+", 36, 36, 36, 36, 0, 493, 0, 89, 0, 89], ["+", 36, 36, 36, 36, 0, 493, 0, 89, 15, 22], ["-", 36, 36, 0, 493, 0, 662, 12, 652, 486, 22], ["+", 0, 89, 8, 170, 0, 662, 12, 652, 486, 744], ["+", 36, 36, 0, 493, 0, 89, 8, 170, 0, 444]]
4
38
5
def solve(x): B=list(map(int,x)) B.reverse() for i in range(len(B)): B[i]=B[i]*(2**i) if 0 in B: B.remove(0) print(" ".join(map(str,B))) while True: try: x=int(input()) solve(format(x,'b')) except EOFError: break
def solve(x): B=list(map(int,x)) B.reverse() for i in range(len(B)): B[i]=B[i]*(2**i) #remove 0 while 0 in B: B.remove(0) print(" ".join(map(str,B))) while True: try: x=int(input()) solve(format(x,'b')) except EOFError: break
[["-", 0, 656, 0, 14, 8, 196, 0, 57, 0, 121], ["+", 0, 656, 0, 14, 8, 196, 0, 52, 0, 89]]
5
103
2
g = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] while True : try : c = -1 left, right = int(input()), [] while True : if left <= 0 : break else : if left - g[c] < 0 : c += -1 else : left -= g[c] right.append(g[c]) right.sort() print(right) except : break
g = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] while True : try : c = -1 left, right = int(input()), [] while True : if left <= 0 : break else : if left - g[c] < 0 : c += -1 else : left -= g[c] right.append(g[c]) right.sort() print(*right) except : break
[["+", 0, 1, 0, 652, 3, 4, 0, 661, 0, 48]]
5
99
1
w_a = [2,4,8,16,32,64,128,256,512] while True: try: w_b = int(input()) b = list(bin(w_b))[::-1] w_c = [] for i in range(len(b)): if b[i] == "b": break elif b[i] == "1": w_c.append(w_a[i]) print(*w_c) except: break
w_a = [1,2,4,8,16,32,64,128,256,512] while True: try: w_b = int(input()) b = list(bin(w_b))[::-1] w_c = [] for i in range(len(b)): if b[i] == "b": break elif b[i] == "1": w_c.append(w_a[i]) print(*w_c) except: break
[["+", 0, 656, 0, 1, 0, 662, 12, 634, 0, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 634, 0, 21]]
5
102
2
import sys print("\n".join((" ".join(str(2**i)for i, n in enumerate(bin(int(s))[:1:-1])if n)for s in sys.stdin.readlines())))
import sys print("\n".join((" ".join(str(2**i)for i, n in enumerate(bin(int(s))[:1:-1])if n=="1")for s in sys.stdin.readlines())))
[["+", 8, 652, 3, 668, 0, 678, 0, 666, 667, 60], ["+", 3, 668, 0, 678, 0, 666, 0, 557, 0, 654], ["+", 3, 668, 0, 678, 0, 666, 0, 557, 0, 6], ["+", 3, 668, 0, 678, 0, 666, 0, 557, 0, 655]]
5
61
4
while True: try: l = []; n = eval(input()); for i in range(10): if ((n >> i) & 1) == 1: l.append(1 << i); print(" ".join(l)) except: break
while True: try: l = []; n = eval(input()); for i in range(10): if ((n >> i) & 1) == 1: l.append(1 << i); print(" ".join(map(str, l))) except: break
[["+", 3, 4, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 21], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
63
5
#!/usr/bin/env import sys weights = [2 ** n for n in range(0, 9)] weights.reverse() while True: try: m = int(input()) except EOFError: break s = [] for w in weights: if w <= m: s.append(w) m -= w s.reverse() print(' '.join(map(str, s)))
#!/usr/bin/env import sys weights = [2 ** n for n in range(0, 10)] weights.reverse() while True: try: m = int(input()) except EOFError: break s = [] for w in weights: if w <= m: s.append(w) m -= w s.reverse() print(' '.join(map(str, s)))
[["-", 12, 658, 0, 659, 12, 652, 3, 4, 0, 612], ["+", 12, 658, 0, 659, 12, 652, 3, 4, 0, 612]]
5
85
2
W=[1,2,4,8,16,32,64,128,256,512] import sys for s in sys.stdin: B=format(int(s),'b') i=0 for e in B: if e=="1": print(W[i], end=' ') i+=1 print()
W=[1,2,4,8,16,32,64,128,256,512] import sys for s in sys.stdin: B=format(int(s),'b')[::-1] i=0 for e in B: if e=="1": print(W[i], end=' ') i+=1 print()
[["+", 8, 196, 0, 1, 0, 662, 12, 206, 0, 70], ["+", 0, 1, 0, 662, 12, 206, 206, 663, 0, 102], ["+", 0, 662, 12, 206, 206, 663, 0, 664, 17, 33], ["+", 0, 662, 12, 206, 206, 663, 0, 664, 28, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 206, 0, 73]]
5
79
6
import sys,math for v in sys.stdin: m=int(v) for i in range(10): if m&(2**i): print(2**i, end=' ')
import sys,math for v in sys.stdin: m=int(v) for i in range(10): if m&(2**i): print(2**i, end=' ') print()
[["+", 0, 7, 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, 25]]
5
46
3
var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var lines = input.trim().split('\n'); var line; var rectangles = 0; var lozenges = 0; while (line = lines.shift()) { var l = line.split(',').map(function(n) { return +n; }); var a = l[0]; var b = l[1]; var c = l[2]; if (a * a + b * b == c * c) rectangles++; else if (a == b) lozenges++; } console.log(rectangles, lozenges);
var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var lines = input.trim().split('\n'); var line; var rectangles = 0; var lozenges = 0; while (line = lines.shift()) { var l = line.split(',').map(function(n) { return +n; }); var a = l[0]; var b = l[1]; var c = l[2]; if (a * a + b * b == c * c) rectangles++; else if (a == b) lozenges++; } console.log(rectangles); console.log(lozenges);
[["-", 0, 493, 0, 1, 0, 2, 3, 3, 0, 21], ["+", 0, 493, 0, 1, 0, 2, 3, 3, 0, 25], ["+", 36, 36, 36, 36, 0, 493, 0, 1, 0, 35], ["+", 0, 493, 0, 1, 0, 2, 63, 558, 500, 22], ["+", 0, 493, 0, 1, 0, 2, 63, 558, 0, 131], ["+", 0, 493, 0, 1, 0, 2, 63, 558, 559, 560], ["+", 0, 493, 0, 1, 0, 2, 3, 3, 0, 24]]
2
148
7
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; public class Main { public static void main(String args[]) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { String line; int recC = 0, lozC = 0; while ((line = br.readLine()) != null) { if (line.equals("")) break; String[] splited = line.split(" "); int n1 = Integer.parseInt(splited[0]); int n2 = Integer.parseInt(splited[1]); int n3 = Integer.parseInt(splited[2]); if (n1 * n1 + n2 * n2 == n3 * n3) recC++; if (n1 == n2) lozC++; } System.out.println(recC); System.out.println(lozC); } catch (Exception e) { e.printStackTrace(); } } }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; public class Main { public static void main(String args[]) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { String line; int recC = 0, lozC = 0; while ((line = br.readLine()) != null) { if (line.equals("")) break; String[] splited = line.split(","); int n1 = Integer.parseInt(splited[0]); int n2 = Integer.parseInt(splited[1]); int n3 = Integer.parseInt(splited[2]); if (n1 * n1 + n2 * n2 == n3 * n3) recC++; if (n1 == n2) lozC++; } System.out.println(recC); System.out.println(lozC); } catch (Exception e) { e.printStackTrace(); } } }
[["-", 49, 200, 51, 492, 3, 4, 0, 5, 0, 491], ["+", 49, 200, 51, 492, 3, 4, 0, 5, 0, 491]]
3
220
2
import java.util.*; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int ans0 = 0; int ans1 = 0; while (stdIn.hasNext()) { String tmp = stdIn.next(); String[] tmp2 = tmp.split(","); int a = Integer.parseInt(tmp2[0]); int b = Integer.parseInt(tmp2[1]); int c = Integer.parseInt(tmp2[2]); if (a * a + b * b == c * c) { ans0++; } else { if (a == b) { ans1++; } } } System.out.println(ans0 + " " + ans1); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int ans0 = 0; int ans1 = 0; while (stdIn.hasNext()) { String tmp = stdIn.next(); String[] tmp2 = tmp.split(","); int a = Integer.parseInt(tmp2[0]); int b = Integer.parseInt(tmp2[1]); int c = Integer.parseInt(tmp2[2]); if (a * a + b * b == c * c) { ans0++; } else { if (a == b) { ans1++; } } } System.out.println(ans0 + "\n" + ans1); } }
[["-", 3, 4, 0, 16, 31, 16, 12, 5, 0, 491], ["+", 3, 4, 0, 16, 31, 16, 12, 5, 0, 44]]
3
165
2
import java.io.*; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int rec = 0; int loz = 0; String line; while ((line = br.readLine()) != null) { String[] value = line.split(","); int s1 = Integer.parseInt(value[0]); int s2 = Integer.parseInt(value[1]); int d = Integer.parseInt(value[2]); if (d == (int)Math.hypot(s1, s2)) { rec++; } if (s1 == s2) { loz++; } } System.out.println(rec); System.out.println(loz); } }
import java.io.*; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int rec = 0; int loz = 0; String line; while ((line = br.readLine()) != null) { String[] value = line.split(","); int s1 = Integer.parseInt(value[0]); int s2 = Integer.parseInt(value[1]); int d = Integer.parseInt(value[2]); if (d == Math.hypot(s1, s2)) { rec++; } if (s1 == s2) { loz++; } } System.out.println(rec); System.out.println(loz); } }
[["-", 0, 57, 15, 15, 0, 16, 12, 74, 0, 24], ["-", 15, 15, 0, 16, 12, 74, 39, 506, 0, 507], ["-", 0, 57, 15, 15, 0, 16, 12, 74, 0, 25]]
3
172
3
import java.io.*; import java.lang.*; import java.util.*; public class Main { public static void main(String[] arg) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); String line; StringTokenizer token1; int a[] = new int[3]; int sum1 = 0, sum2 = 0; while ((line = input.readLine()) != null && !line.isEmpty()) { token1 = new StringTokenizer(line, ","); for (int i = 0; i < 3; i++) { a[i] = Integer.parseInt(token1.nextToken()); } // Arrays.sort(a); if (a[1] * a[1] + a[0] * a[0] == a[2] * a[2]) { sum1++; } if (a[2] == a[1]) { sum2++; } } System.out.println(sum1); System.out.println(sum2); } }
import java.io.*; import java.lang.*; import java.util.*; public class Main { public static void main(String[] arg) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); String line; StringTokenizer token1; int a[] = new int[3]; int sum1 = 0, sum2 = 0; while ((line = input.readLine()) != null && !line.isEmpty()) { token1 = new StringTokenizer(line, ","); for (int i = 0; i < 3; i++) { a[i] = Integer.parseInt(token1.nextToken()); } // Arrays.sort(a); if (a[1] * a[1] + a[0] * a[0] == a[2] * a[2]) { sum1++; } if (a[1] == a[0]) { sum2++; } } System.out.println(sum1); System.out.println(sum2); } }
[["-", 0, 57, 15, 15, 0, 16, 31, 504, 71, 499], ["+", 0, 57, 15, 15, 0, 16, 31, 504, 71, 499], ["-", 0, 57, 15, 15, 0, 16, 12, 504, 71, 499], ["+", 0, 57, 15, 15, 0, 16, 12, 504, 71, 499]]
3
221
4
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str; int sq = 0, hi = 0; int a, b, c; while (scan.hasNext()) { str = scan.next(); String[] num = str.split(",", 0); a = Integer.parseInt(num[0]); b = Integer.parseInt(num[1]); c = Integer.parseInt(num[2]); if (a * a + b * b == c * c) sq++; else if (a == b) hi++; } System.out.println(sq); System.out.println(sq); } }
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str; int sq = 0, hi = 0; int a, b, c; while (scan.hasNext()) { str = scan.next(); String[] num = str.split(",", 0); a = Integer.parseInt(num[0]); b = Integer.parseInt(num[1]); c = Integer.parseInt(num[2]); if (a * a + b * b == c * c) sq++; else if (a == b) hi++; } System.out.println(sq); System.out.println(hi); } }
[["-", 8, 196, 0, 1, 0, 492, 3, 4, 0, 22], ["+", 8, 196, 0, 1, 0, 492, 3, 4, 0, 22]]
3
168
2
import java.util.*; public class Main { private static final Scanner scan = new Scanner(System.in).useDelimiter("[,\\s+]"); public static void main(String[] args) { int r = 0; int d = 0; while (scan.hasNext()) { int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); if ((double)c == Math.hypot((double)a, (double)b)) { r++; } if (a == b) { d++; } System.out.printf("%d\n", r); System.out.printf("%d\n", d); } } }
import java.util.*; public class Main { private static final Scanner scan = new Scanner(System.in).useDelimiter("[,\\s+]"); public static void main(String[] args) { int r = 0; int d = 0; while (scan.hasNext()) { int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); if ((double)c == Math.hypot((double)a, (double)b)) { r++; } if (a == b) { d++; } } System.out.printf("%d\n", r); System.out.printf("%d\n", d); } }
[["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
3
160
2
import java.io.*; public class Main { public static void main(String[] args) throws IOException { int hishi = 0; int tyou = 0; String check; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while ((check = br.readLine()) != null) { String[] str = new String[3]; str = check.split(","); int[] hen = new int[3]; hen[0] = Integer.parseInt(str[0]); hen[1] = Integer.parseInt(str[1]); hen[2] = Integer.parseInt(str[2]); if (hen[0] * hen[0] + hen[1] * hen[1] == hen[2] * hen[2]) tyou++; if (hen[0] == hen[1] && (hen[0] + hen[1] > hen[2] || Math.abs(hen[0] - hen[1]) < hen[2])) hishi++; System.out.println(tyou + "\n" + hishi); } } }
import java.io.*; public class Main { public static void main(String[] args) throws IOException { int hishi = 0; int tyou = 0; String check; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while ((check = br.readLine()) != null) { String[] str = new String[3]; str = check.split(","); int[] hen = new int[3]; hen[0] = Integer.parseInt(str[0]); hen[1] = Integer.parseInt(str[1]); hen[2] = Integer.parseInt(str[2]); if (hen[0] * hen[0] + hen[1] * hen[1] == hen[2] * hen[2]) tyou++; if (hen[0] == hen[1] && (hen[0] + hen[1] > hen[2] || Math.abs(hen[0] - hen[1]) < hen[2])) hishi++; } System.out.println(tyou + "\n" + hishi); } }
[["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
3
250
2
#include <stdio.h> int main() { int a, b, c, i, j; i = 0; j = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a + b > c && b + c > a && a + c > b) { if (a * a == b * b + c * c) i++; if (a == b) j++; } } printf("%d\n%d\n", i, j); return 0; }
#include <stdio.h> int main() { int a, b, c, i, j; i = 0; j = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a + b > c && b + c > a && a + c > b) { if (a * a + b * b == c * c) i++; if (a == b) j++; } } printf("%d\n%d\n", i, j); return 0; }
[["-", 64, 9, 0, 57, 15, 23, 0, 16, 17, 60], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 72], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 72], ["+", 64, 9, 0, 57, 15, 23, 0, 16, 17, 60]]
0
114
4
#include <stdio.h> int main(void) { int a, b, c; int rectangle, diamond; rectangle = diamond = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a * a + b * b == c * c) { rectangle++; } else if (a == b) { diamond++; } } printf("%d %d\n", rectangle, diamond); return 0; }
#include <stdio.h> int main(void) { int a, b, c; int rectangle, diamond; rectangle = diamond = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a * a + b * b == c * c) { rectangle++; } if (a == b) { diamond++; } } printf("%d\n%d\n", rectangle, diamond); return 0; }
[["-", 0, 52, 8, 9, 0, 57, 75, 76, 0, 95], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
95
5
#include <stdio.h> int main(void) { int a, b, tai; int tyou = 0; int hisi = 0; while (scanf("%d", &a) != EOF) { scanf(",%d,%d", &b, &tai); if (tai * tai == a * a + b * b) { tyou++; } if (a == b) { hisi++; } } printf("%d %d\n", tyou, hisi); return (0); }
#include <stdio.h> int main(void) { int a, b, tai; int tyou = 0; int hisi = 0; while (scanf("%d", &a) != EOF) { scanf(",%d,%d", &b, &tai); if (tai * tai == a * a + b * b) { tyou++; } if (a == b) { hisi++; } } printf("%d\n%d\n", tyou, hisi); return (0); }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
102
4
#include <stdio.h> int main(void) { int length[3]; int rectangle, diamond; rectangle = diamond = 0; while (scanf("%d,%d,%d", &length[0], &length[1], &length[2]) != EOF) { if ((length[0] * length[0]) + (length[1] * length[1]) == (length[2] * length[2])) { rectangle++; } else if (length[0] == length[1]) { diamond++; } } printf("%d %d\n", rectangle, diamond); return (0); }
#include <stdio.h> int main(void) { int length[3]; int rectangle, diamond; rectangle = diamond = 0; while (scanf("%d,%d,%d", &length[0], &length[1], &length[2]) != EOF) { if ((length[0] * length[0]) + (length[1] * length[1]) == (length[2] * length[2])) { rectangle++; } else if (length[0] == length[1]) { diamond++; } } printf("%d\n%d\n", rectangle, diamond); return (0); }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
135
4
#include <stdio.h> main() { int a, b, c, m = 0, n = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a != b && (a < c || b < c) && (a + b) > c && (a * a + b * b) == c * c) n++; else if (a == b && a < c && (a + b) > c) m++; } printf("%d\n%d\n", n, m); return 0; }
#include <stdio.h> main() { int a, b, c, m = 0, n = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a != b && (a < c || b < c) && (a + b) > c && (a * a + b * b) == c * c) n++; else if (a == b && (a + b) > c) m++; } printf("%d\n%d\n", n, m); return 0; }
[["-", 15, 23, 0, 16, 31, 16, 12, 16, 31, 22], ["-", 15, 23, 0, 16, 31, 16, 12, 16, 17, 18], ["-", 15, 23, 0, 16, 31, 16, 12, 16, 12, 22], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 17, 98]]
0
125
4
#include <stdio.h> #include <stdlib.h> #include <string.h> int i, j, k; int n[5], ans1 = 0, ans2 = 0; int main() { while (scanf("%d,%d,%d", &n[0], &n[1], &n[2]) != EOF) { if (n[0] == n[1]) ans1++; else if (n[0] * n[0] + n[1] * n[1] == n[2] * n[2]) ans2++; } printf("%d\n%d\n", ans1, ans2); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int i, j, k; int n[5], ans1 = 0, ans2 = 0; int main() { while (scanf("%d,%d,%d", &n[0], &n[1], &n[2]) != EOF) { if (n[0] == n[1]) ans1++; else if (n[0] * n[0] + n[1] * n[1] == n[2] * n[2]) ans2++; } printf("%d\n%d\n", ans2, ans1); 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
132
4
t, h; int main(a, b, c, d) { for (; ~scanf("%d,%d,%d", &a, &b, &c);) { if (c * c == a * a + b * b) t++; if (a == b && a <= c) h++; } printf("%d\n%d\n", t, h); exit(0); }
t, h; int main(a, b, c, d) { for (; ~scanf("%d,%d,%d", &a, &b, &c);) { if (c * c == a * a + b * b) t++; if (a == b) h++; } printf("%d\n%d\n", t, h); exit(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, 19], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 12, 22]]
0
89
4
#include <stdio.h> int main(void) { int a, b, c; int conlec = 0; int conhisi = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a * a + b * b == c * c) conlec++; else if (a == b) conhisi++; }; printf("%d %d\n", conlec, conhisi); return (0); }
#include <stdio.h> int main(void) { int a, b, c; int conlec = 0; int conhisi = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a * a + b * b == c * c) conlec++; else if (a == b) conhisi++; }; printf("%d\n%d\n", conlec, conhisi); return (0); }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
93
4
#include <stdio.h> int main() { int a, b, c, t = 0, h = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a + b >= c) continue; else if (a * a + b * b == c * c) t++; else if (a == b) h++; } printf("%d\n%d\n", t, h); }
#include <stdio.h> int main() { int a, b, c, t = 0, h = 0; while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a + b <= c) continue; else if (a * a + b * b == c * c) t++; else if (a == b) h++; } printf("%d\n%d\n", t, h); return 0; }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 19], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 13]]
0
97
5
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; int main() { int rectangle_num = 0, rhombus_num = 0; int side1, side2, diagonal; while (scanf("%d,%d,%d", &side1, &side2, &diagonal) != EOF) { if (side2 > side1) swap(side1, side2); // 長方形の判定 if (side1 * side1 + side2 * side2 == diagonal * diagonal) { rectangle_num++; } else if (side1 == side2 && !diagonal) { rhombus_num++; } } cout << rectangle_num << endl << rhombus_num << endl; return 0; }
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; int main() { int rectangle_num = 0, rhombus_num = 0; int side1, side2, diagonal; while (scanf("%d,%d,%d", &side1, &side2, &diagonal) != EOF) { if (side2 > side1) swap(side1, side2); // 長方形の判定 if (side1 * side1 + side2 * side2 == diagonal * diagonal) { rectangle_num++; } else if (side1 == side2) { rhombus_num++; } } cout << rectangle_num << endl << rhombus_num << endl; return 0; }
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 98], ["-", 0, 57, 15, 339, 51, 16, 12, 91, 17, 111], ["-", 0, 57, 15, 339, 51, 16, 12, 91, 28, 22]]
1
115
3
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> typedef long long Int; #pragma warning(disable : 4996) #define REP(i, n) for (int i = 0; i < n; ++i) #define REPS(a, i, n) for (int i = a; i < n; ++i) using namespace std; int main() { int a, b, c; int t(0), h(0); while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a + b < c || a + c < b || b + c < a || !a || !b || !c) continue; if (a * a + b * b == c * c) ++t; if (a == b) ++h; cout << t << endl << h << endl; } return 0; }
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> typedef long long Int; #pragma warning(disable : 4996) #define REP(i, n) for (int i = 0; i < n; ++i) #define REPS(a, i, n) for (int i = a; i < n; ++i) using namespace std; int main() { int a, b, c; int t(0), h(0); while (scanf("%d,%d,%d", &a, &b, &c) != EOF) { if (a + b < c || a + c < b || b + c < a || !a || !b || !c) continue; if (a * a + b * b == c * c) ++t; if (a == b) ++h; } cout << t << endl << h << endl; return 0; }
[["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
167
2
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define all(c) (c).begin(), (c).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define pb(e) push_back(e) #define mp(a, b) make_pair(a, b) #define fr first #define sc second const int INF = 100000000; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; using namespace std; typedef pair<int, int> P; typedef long long ll; int main() { int a[3]; int cnt1 = 0, cnt2 = 0; while (~scanf("%d,%d,%d", &a[0], &a[1], &a[2])) { if (a[2] * a[2] == a[0] * a[0] + a[1] * a[1]) cnt1++; if (a[0] == a[1]) cnt2++; } cout << cnt2 << endl; cout << cnt1 << endl; return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define all(c) (c).begin(), (c).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define pb(e) push_back(e) #define mp(a, b) make_pair(a, b) #define fr first #define sc second const int INF = 100000000; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; using namespace std; typedef pair<int, int> P; typedef long long ll; int main() { int a[3]; int cnt1 = 0, cnt2 = 0; while (~scanf("%d,%d,%d", &a[0], &a[1], &a[2])) { if (a[2] * a[2] == a[0] * a[0] + a[1] * a[1]) cnt1++; if (a[0] == a[1]) cnt2++; } cout << cnt1 << endl; cout << cnt2 << endl; return 0; }
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
242
4
#include <cstdio> #include <iostream> using namespace std; int main() { int a, b, c; char com; int t = 0; int h = 0; while (cin >> a >> com >> b >> com >> c) { if (a * a + b * b == c * c) t++; else if (a == b) h++; } cout << t << " " << h << endl; }
#include <cstdio> #include <iostream> using namespace std; int main() { int a, b, c; char com; int t = 0; int h = 0; while (cin >> a >> com >> b >> com >> c) { if (a * a + b * b == c * c) t++; else if (a == b) h++; } cout << t << endl; cout << h << endl; }
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 31, 22]]
1
89
6
#include <iostream> using namespace std; bool Rectangle(int a, int b, int c) { return a * a + b * b == c * c; } bool Diamond(int a, int b, int c) { return a == b || b == c; } int main() { int a, b, c, sum1 = 0, sum2 = 0; char ch; while (cin >> a >> ch >> b >> ch >> c) { if (Rectangle(a, b, c)) sum1++; if (Diamond(a, b, c)) sum2++; } cout << sum1 << endl << sum2 << endl; return 0; }
#include <iostream> using namespace std; bool Rectangle(int a, int b, int c) { return a * a + b * b == c * c; } bool Diamond(int a, int b, int c) { return a == b; } int main() { int a, b, c, sum1 = 0, sum2 = 0; char ch; while (cin >> a >> ch >> b >> ch >> c) { if (Rectangle(a, b, c)) sum1++; if (Diamond(a, b, c)) sum2++; } cout << sum1 << endl << sum2 << endl; return 0; }
[["-", 0, 14, 8, 9, 0, 37, 0, 16, 17, 106], ["-", 8, 9, 0, 37, 0, 16, 12, 16, 31, 22], ["-", 8, 9, 0, 37, 0, 16, 12, 16, 17, 60], ["-", 8, 9, 0, 37, 0, 16, 12, 16, 12, 22]]
1
137
4