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
|
|---|---|---|---|---|---|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args)
throws NumberFormatException, IOException {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
while (input.ready()) {
String[] INPUT_STR = input.readLine().split(" ");
int numCount = Integer.valueOf(INPUT_STR[0]);
int sumNumber = Integer.valueOf(INPUT_STR[1]);
if (sumNumber == 0) {
break;
}
int ans = solver(numCount, sumNumber);
System.out.println(ans);
}
}
private static int solver(int numCount, int sumNumber) {
return solver(numCount, sumNumber, 0, 0);
}
private static int solver(int numCount, int sumNumber, int currentSum,
int startIndex) {
int ret = 0;
if (numCount - 1 == 0) {
for (int i = startIndex; i < 10; i++) {
if (currentSum + i == sumNumber) {
ret++;
}
}
}
for (int i = startIndex; i < 10; i++) {
ret += solver(numCount - 1, sumNumber, currentSum + i, i + 1);
}
return ret;
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args)
throws NumberFormatException, IOException {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
while (input.ready()) {
String[] INPUT_STR = input.readLine().split(" ");
int numCount = Integer.valueOf(INPUT_STR[0]);
int sumNumber = Integer.valueOf(INPUT_STR[1]);
if (numCount == 0 && sumNumber == 0) {
break;
}
int ans = solver(numCount, sumNumber);
System.out.println(ans);
}
}
private static int solver(int numCount, int sumNumber) {
return solver(numCount, sumNumber, 0, 0);
}
private static int solver(int numCount, int sumNumber, int currentSum,
int startIndex) {
int ret = 0;
if (numCount - 1 == 0) {
for (int i = startIndex; i < 10; i++) {
if (currentSum + i == sumNumber) {
ret++;
}
}
}
for (int i = startIndex; i < 10; i++) {
ret += solver(numCount - 1, sumNumber, currentSum + i, i + 1);
}
return ret;
}
}
|
[["+", 0, 57, 15, 15, 0, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 15, 0, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 15, 0, 16, 31, 16, 12, 499], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 98]]
| 3
| 266
| 4
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
int s = sc.nextInt();
if (n == 0 && s == 0)
break;
int ans = solve(n, s, 0);
System.out.println(ans);
}
}
public static int solve(int n, int s, int c) {
if (n == 1 && s >= c && s < 10)
return 1;
if (n == 1)
return 0;
int sum = 0;
for (int i = c; i < 10 && i < s; i++) {
sum += solve(n - 1, s - 1, i + 1);
}
return sum;
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
int s = sc.nextInt();
if (n == 0 && s == 0)
break;
int ans = solve(n, s, 0);
System.out.println(ans);
}
}
public static int solve(int n, int s, int c) {
if (n == 1 && s >= c && s < 10)
return 1;
if (n == 1)
return 0;
int sum = 0;
for (int i = c; i < 10 && i < s; i++) {
sum += solve(n - 1, s - i, i + 1);
}
return sum;
}
}
|
[["-", 0, 11, 12, 492, 3, 4, 0, 16, 12, 499], ["+", 0, 11, 12, 492, 3, 4, 0, 16, 12, 22]]
| 3
| 179
| 2
|
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static int rec(int n, int k) {
int r = 0;
for (int i = 1; i < (1 << 10); i++) {
int c = Integer.bitCount(i);
int sum = 0;
if (c == n)
for (int j = 0; j < 10; j++)
if ((i & (1 << j)) != 0)
sum += j;
if (sum == k)
r++;
}
return r;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
while (true) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
if (n == 0 && k == 0)
break;
System.out.println(rec(n, k));
}
}
}
|
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static int rec(int n, int k) {
int r = 0;
for (int i = 1; i < (1 << 10); i++) {
int c = Integer.bitCount(i);
int sum = 0;
if (c == n) {
for (int j = 0; j < 10; j++)
if ((i & (1 << j)) != 0)
sum += j;
if (sum == k)
r++;
}
}
return r;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
while (true) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
if (n == 0 && k == 0)
break;
System.out.println(rec(n, k));
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 3
| 226
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (true) {
int n = input.nextInt();
int s = input.nextInt();
if (n == 0 && s == 0)
break;
System.out.println(count(n, s, 0, 0));
}
}
public static int count(int n, int s, int sum, int stnum) {
if (n == 0 && sum == s)
return 1;
if (stnum == 10 || sum >= s || n == 0)
return 0;
return count(n - 1, s, sum + stnum, stnum + 1) +
count(n, s, sum, stnum + 1);
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (true) {
int n = input.nextInt();
int s = input.nextInt();
if (n == 0 && s == 0)
break;
System.out.println(count(n, s, 0, 0));
}
}
public static int count(int n, int s, int sum, int stnum) {
if (n == 0 && sum == s)
return 1;
if (stnum == 10 || sum > s || n == 0)
return 0;
return count(n - 1, s, sum + stnum, stnum + 1) +
count(n, s, sum, stnum + 1);
}
}
|
[["-", 15, 15, 0, 16, 31, 16, 12, 16, 17, 20], ["+", 15, 15, 0, 16, 31, 16, 12, 16, 17, 47]]
| 3
| 169
| 2
|
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
while (true) {
final int n = stdin.nextInt();
final int sum = stdin.nextInt();
if (n == 0 && sum == 0) {
break;
}
System.out.println(dfs(0, n, 0, sum, -1));
}
}
static int dfs(final int depth, final int maxDepth, final int sum,
final int maxSum, final int maxNum) {
if (depth == maxDepth) {
return (sum == maxSum ? 1 : 0);
}
int ans = 0;
final int lim = Math.max(maxSum - sum, 9);
for (int i = maxNum + 1; i <= lim; i++) {
ans += dfs(depth + 1, maxDepth, sum + i, maxSum, i);
}
return ans;
}
}
|
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
while (true) {
final int n = stdin.nextInt();
final int sum = stdin.nextInt();
if (n == 0 && sum == 0) {
break;
}
System.out.println(dfs(0, n, 0, sum, -1));
}
}
static int dfs(final int depth, final int maxDepth, final int sum,
final int maxSum, final int maxNum) {
if (depth == maxDepth) {
return (sum == maxSum ? 1 : 0);
}
int ans = 0;
final int lim = Math.min(maxSum - sum, 9);
for (int i = maxNum + 1; i <= lim; i++) {
ans += dfs(depth + 1, maxDepth, sum + i, maxSum, i);
}
return ans;
}
}
|
[["-", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22]]
| 3
| 207
| 2
|
import java.util.*;
public class Main {
public static void main(String[] args) { new Main().run(); }
Scanner sc = new Scanner(System.in);
int n, s;
int ans;
void run() {
while (sc.hasNext()) {
n = sc.nextInt();
s = sc.nextInt();
if (n != 0) {
ans = 0;
solve(0, 0, 0);
System.out.println(ans);
}
}
}
void solve(int level, int sum, int use) {
if (use == n) {
if (sum == s)
ans++;
return;
}
if (level > 10 || use > n || sum > s)
return;
solve(level + 1, sum + level, use + 1);
solve(level + 1, sum, use);
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) { new Main().run(); }
Scanner sc = new Scanner(System.in);
int n, s;
int ans;
void run() {
while (sc.hasNext()) {
n = sc.nextInt();
s = sc.nextInt();
if (n != 0) {
ans = 0;
solve(0, 0, 0);
System.out.println(ans);
}
}
}
void solve(int level, int sum, int use) {
if (use == n) {
if (sum == s)
ans++;
return;
}
if (level >= 10 || use > n || sum > s)
return;
solve(level + 1, sum + level, use + 1);
solve(level + 1, sum, use);
}
}
|
[["-", 15, 15, 0, 16, 31, 16, 31, 16, 17, 47], ["+", 15, 15, 0, 16, 31, 16, 31, 16, 17, 20]]
| 3
| 189
| 2
|
#include <stdio.h>
int n, s, count = 0, digits[10];
void dfs(int cur, int start) {
if (cur == n) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += digits[i];
}
if (sum == s) {
count++;
}
return;
}
for (int i = start; i < 10; i++) {
digits[cur] = i;
dfs(cur + 1, i + 1);
}
}
int main(void) {
while (scanf("%d %d", &n, &n) != EOF) {
if (n == 0 && s == 0) {
break;
}
count = 0;
dfs(0, 0);
printf("%d\n", count);
}
return 0;
}
|
#include <stdio.h>
int n, s, count = 0, digits[10];
void dfs(int cur, int start) {
if (cur == n) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += digits[i];
}
if (sum == s) {
count++;
}
return;
}
for (int i = start; i < 10; i++) {
digits[cur] = i;
dfs(cur + 1, i + 1);
}
}
int main(void) {
while (scanf("%d %d", &n, &s) != EOF) {
if (n == 0 && s == 0) {
break;
}
count = 0;
dfs(0, 0);
printf("%d\n", count);
}
return 0;
}
|
[["-", 0, 16, 31, 2, 3, 4, 0, 66, 28, 22], ["+", 0, 16, 31, 2, 3, 4, 0, 66, 28, 22]]
| 0
| 174
| 2
|
#include <stdio.h>
int a, n, s;
void k(int sum, int c, int j) {
int i;
for (i = 1; i + j < 10; i++) {
sum += (i * c);
c--;
if (c == 0) {
if (sum == s) {
a++;
break;
}
} else
k(sum, c, i + j);
c++;
sum -= i * c;
}
}
int main() {
int i, c, sum = 0;
while (scanf("%d %d", &n, &s)) {
if (n == 0 && s == 0)
break;
a = 0;
c = n;
for (i = 0; i * n < s; i++) {
sum = i * c;
k(sum, c - 1, i);
}
printf("%d\n", a);
}
return 0;
}
|
#include <stdio.h>
int a, n, s;
void k(int sum, int c, int j) {
int i;
for (i = 1; i + j < 10; i++) {
sum += (i * c);
c--;
if (c <= 0) {
if (sum == s) {
a++;
break;
}
} else
k(sum, c, i + j);
c++;
sum -= i * c;
}
}
int main() {
int i, c, sum = 0;
while (scanf("%d %d", &n, &s)) {
if (n == 0 && s == 0)
break;
a = 0;
c = n;
for (i = 0; i * n <= s; i++) {
sum = i * c;
k(sum, c - 1, i);
}
printf("%d\n", a);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 19], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
| 0
| 195
| 4
|
#include <stdio.h>
int ans;
int solve(int i, int sum, int n, int s) {
if (sum == s && n == 0) {
ans++;
return 0;
} else if (i == 10 || n == 0) {
return 0;
} else {
solve(i + 1, sum + i, n - 1, s);
solve(i + 1, sum, n, s);
}
return 0;
}
int main() {
int n, s;
while (scanf("%d %d", &n, &s) && n != 0 && s != 0) {
ans = 0;
solve(0, 0, n, s);
printf("%d\n", ans);
}
return 0;
}
|
#include <stdio.h>
int ans;
int solve(int i, int sum, int n, int s) {
if (sum == s && n == 0) {
ans++;
return 0;
} else if (i == 10 || n == 0) {
return 0;
} else {
solve(i + 1, sum + i, n - 1, s);
solve(i + 1, sum, n, s);
}
return 0;
}
int main() {
int n, s;
while (scanf("%d %d", &n, &s) && (n != 0 || s != 0)) {
ans = 0;
solve(0, 0, n, s);
printf("%d\n", ans);
}
return 0;
}
|
[["+", 0, 52, 15, 23, 0, 16, 12, 23, 0, 24], ["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 52, 15, 23, 0, 16, 12, 23, 0, 25]]
| 0
| 156
| 4
|
#include <stdio.h>
int n, s;
int rec(int sum, int dig, int cnt);
int main() {
while (1) {
scanf("%d %d", &n, &s);
if (n == 0 && s == 0)
break;
printf("%d\n", rec(0, 0, 0));
}
return 0;
}
int rec(int sum, int dig, int cnt) {
if (cnt > n || sum > s)
return 0;
if (cnt == n && sum == s)
return 1;
if (dig > 9)
return 0;
int ret = 0;
ret += rec(sum + dig, dig, cnt);
ret += rec(sum, dig + 1, cnt);
return ret;
}
|
#include <stdio.h>
int n, s;
int rec(int sum, int dig, int cnt);
int main() {
while (1) {
scanf("%d %d", &n, &s);
if (n == 0 && s == 0)
break;
printf("%d\n", rec(0, 0, 0));
}
return 0;
}
int rec(int sum, int dig, int cnt) {
if (cnt > n || sum > s)
return 0;
if (cnt == n && sum == s)
return 1;
if (dig > 9)
return 0;
int ret = 0;
ret += rec(sum + dig, dig + 1, cnt + 1);
ret += rec(sum, dig + 1, cnt);
return ret;
}
|
[["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13]]
| 0
| 160
| 4
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
int f(int n, int s, int a) {
int r, i;
if (n == 1)
if (a <= s && s <= 9)
return 1;
else
return 0;
r = 0;
for (i = a; i <= 9 && i < s; i++)
r += f(n - 1, s - i, i + 1);
return r;
}
int main() {
FILE *fp = stdin;
int n, s;
while (fscanf(fp, "%d%d", &n, &s) && n && s) {
printf("%d\n", f(n, s, 0));
}
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
int f(int n, int s, int a) {
int r, i;
if (n == 1)
if (a <= s && s <= 9)
return 1;
else
return 0;
r = 0;
for (i = a; i <= 9 && i < s; i++)
r += f(n - 1, s - i, i + 1);
return r;
}
int main() {
FILE *fp = stdin;
int n, s;
while (fscanf(fp, "%d%d", &n, &s) && (n || s)) {
fprintf(stdout, "%d\n", f(n, s, 0));
}
return 0;
}
|
[["+", 0, 52, 15, 23, 0, 16, 12, 23, 0, 24], ["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 52, 15, 23, 0, 16, 12, 23, 0, 25], ["-", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21]]
| 0
| 149
| 8
|
#include <stdio.h>
int i, n, s;
void part(int cal, int index, int sum) {
if (index == 9 && cal == n && sum == s) {
i++;
return;
}
if (index > 9 || cal > n || sum > s)
return;
part(cal, index + 1, sum);
part(cal + 1, index + 1, sum + index);
}
main() {
while (1) {
scanf("%d %d", &n, &s);
if (n == 0 && s == 0)
return 0;
i = 0;
part(0, 0, 0);
printf("%d\n", i);
}
return 0;
}
|
#include <stdio.h>
int i, n, s;
void part(int cal, int index, int sum) {
if (index == 10 && cal == n && sum == s) {
i++;
return;
}
if (index > 9 || cal > n || sum > s)
return;
part(cal, index + 1, sum);
part(cal + 1, index + 1, sum + index);
}
main() {
while (1) {
scanf("%d %d", &n, &s);
if (n == 0 && s == 0)
return 0;
i = 0;
part(0, 0, 0);
printf("%d\n", i);
}
return 0;
}
|
[["-", 15, 23, 0, 16, 31, 16, 31, 16, 12, 13], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 12, 13]]
| 0
| 150
| 2
|
#include <stdio.h>
int count;
int sumofintegers(int N, int S, int I) {
/*printf("N%d S%d I%d\n", N, S, I);*/
if (N == 0 && S == 0)
count++;
else if (N > 0 && S >= 0 && I < 9) {
sumofintegers(N, S, I + 1);
if (S - I >= 0)
sumofintegers(N - 1, S - I, I + 1);
}
return count;
}
int main(void) {
int n, s, i = 0;
scanf("%d %d", &n, &s);
while (1) {
i = 0;
printf("%d\n", sumofintegers(n, s, i));
scanf("%d %d", &n, &s);
if (n == 0 && s == 0)
break;
count = 0;
}
return 0;
}
|
#include <stdio.h>
int count;
int sumofintegers(int N, int S, int I) {
/*printf("N%d S%d I%d\n", N, S, I);*/
if (N == 0 && S == 0)
count++;
else if (N > 0 && S >= 0 && I <= 9) {
sumofintegers(N, S, I + 1);
if (S - I >= 0)
sumofintegers(N - 1, S - I, I + 1);
}
return count;
}
int main(void) {
int n, s, i = 0;
scanf("%d %d", &n, &s);
while (1) {
i = 0;
printf("%d\n", sumofintegers(n, s, i));
scanf("%d %d", &n, &s);
if (n == 0 && s == 0)
break;
count = 0;
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 19]]
| 0
| 175
| 2
|
#include <stdio.h>
int n, s, count = 0;
int digits[10];
void dfs(int cur, int start) {
if (cur == n) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += digits[i];
}
if (sum == s) {
count++;
}
return;
}
for (int i = start; i < 10; i++) {
digits[cur] = i;
dfs(cur + 1, i + 1);
}
}
int main(void) {
while (1) {
scanf("%d %d", &n, &s);
if (n == 0 || s == 0) {
break;
}
count = 0;
dfs(0, 0);
printf("%d\n", count);
}
return (0);
}
|
#include <stdio.h>
int n, s, count = 0;
int digits[10];
void dfs(int cur, int start) {
if (cur == n) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += digits[i];
}
if (sum == s) {
count++;
}
return;
}
for (int i = start; i < 10; i++) {
digits[cur] = i;
dfs(cur + 1, i + 1);
}
}
int main(void) {
while (1) {
scanf("%d %d", &n, &s);
if (n == 0 && s == 0) {
break;
}
count = 0;
dfs(0, 0);
printf("%d\n", count);
}
return (0);
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 106], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98]]
| 0
| 177
| 2
|
#include <stdio.h>
int n, s;
int sum, count, ans, data[10];
void rec(int);
void rec(int p) {
if (p > 9) {
return;
}
if (count == n) {
if (s == sum)
ans++;
return;
}
data[p] = 1;
sum += p;
count++;
rec(p + 1);
sum -= p;
count--;
data[p] = 0;
rec(p + 1);
}
main() {
while (1) {
scanf("%d %d", &n, &s);
if (n == 0 && s == 0)
break;
ans = count = sum = 0;
rec(0);
printf("%d\n", ans);
}
return 0;
}
|
#include <stdio.h>
int n, s;
int sum, count, ans, data[11];
void rec(int);
void rec(int p) {
if (p > 10) {
return;
}
if (count == n) {
if (s == sum)
ans++;
return;
}
data[p] = 1;
sum += p;
count++;
rec(p + 1);
sum -= p;
count--;
data[p] = 0;
rec(p + 1);
}
main() {
while (1) {
scanf("%d %d", &n, &s);
if (n == 0 && s == 0)
break;
ans = count = sum = 0;
rec(0);
printf("%d\n", ans);
}
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 167
| 4
|
m;
f(r, n, i, t) {
for (; i++ < 9;)
t += f(r - i, n - 1, i, 0);
return n - 1 ? t : !r;
}
main(s) {
for (; scanf("%d%d", &m, &s), m; printf("%d\n", f(s, m, -1, 0)))
;
}
|
m;
f(r, n, i, t) {
for (; i++ < 9;)
t += f(r - i, n - 1, i, 0);
return n ? t : !r;
}
main(s) {
for (; scanf("%d%d", &m, &s), m; printf("%d\n", f(s, m, -1, 0)))
;
}
|
[["-", 0, 9, 0, 37, 0, 41, 15, 16, 17, 33], ["-", 0, 9, 0, 37, 0, 41, 15, 16, 12, 13]]
| 0
| 95
| 2
|
#include <stdio.h>
int func(int, int, int);
int s;
int main(void) {
int n, i;
while (scanf("%d %d", &n, &s), n, s) {
printf("%d\n", func(0, 0, n));
}
return 0;
}
int func(int now, int sum, int num) {
int count = 0;
if (!num)
return s == sum ? 1 : 0;
if (now == 10 || !num || sum > s)
return 0;
count += func(now + 1, sum + now, num - 1);
count += func(now + 1, sum, num);
return count;
}
|
#include <stdio.h>
int func(int, int, int);
int s;
int main(void) {
int n, i;
while (scanf("%d %d", &n, &s), n) {
printf("%d\n", func(0, 0, n));
}
return 0;
}
int func(int now, int sum, int num) {
int count = 0;
if (!num)
return s == sum ? 1 : 0;
if (now == 10 || !num || sum > s)
return 0;
count += func(now + 1, sum + now, num - 1);
count += func(now + 1, sum, num);
return count;
}
|
[["-", 0, 52, 15, 23, 0, 34, 12, 34, 0, 21], ["-", 0, 52, 15, 23, 0, 34, 12, 34, 12, 22]]
| 0
| 150
| 2
|
#include <stdio.h>
void plus(int start, int end, int sum, int np, int sp);
int count;
int main() {
int i, n, s;
while (scanf("%d %d", &n, &s) != EOF) {
if (n && s)
break;
count = 0;
for (i = 0; i < 11 - n; i++) {
if (n == 1) {
if (i == s) {
count++;
break;
}
} else
plus(i + 1, 2, i, n, s);
}
printf("%d\n", count);
}
return 0;
}
void plus(int start, int end, int sum, int np, int sp) {
int i;
for (i = start; i < 10 - np + end; i++) {
if (np == end) {
if (sum + i == sp) {
count++;
return;
}
} else
plus(i + 1, end + 1, sum + i, np, sp);
}
}
|
#include <stdio.h>
void plus(int start, int end, int sum, int np, int sp);
int count;
int main() {
int i, n, s;
while (scanf("%d %d", &n, &s) != EOF) {
if (!n && !s)
break;
count = 0;
for (i = 0; i < 11 - n; i++) {
if (n == 1) {
if (i == s) {
count++;
break;
}
} else
plus(i + 1, 2, i, n, s);
}
printf("%d\n", count);
}
return 0;
}
void plus(int start, int end, int sum, int np, int sp) {
int i;
for (i = start; i < 10 - np + end; i++) {
if (np == end) {
if (sum + i == sp) {
count++;
return;
}
} else
plus(i + 1, end + 1, sum + i, np, sp);
}
}
|
[["+", 0, 57, 15, 23, 0, 16, 31, 91, 17, 111], ["+", 0, 57, 15, 23, 0, 16, 12, 91, 17, 111]]
| 0
| 220
| 2
|
#include <stdio.h>
int cnt = 0, n, s;
void func(int sum, int depth, int x) {
int i;
if (depth > n) {
if (sum == s) {
cnt++;
}
return;
}
for (i = x; i < s; i++) {
func(sum + i, depth + 1, i + 1);
}
}
int main(void) {
while (scanf("%d %d", &n, &s), n || s) {
cnt = 0;
func(0, 1, 0);
printf("%d\n", cnt);
}
return 0;
}
|
#include <stdio.h>
int cnt = 0, n, s;
void func(int sum, int depth, int x) {
int i;
if (depth > n) {
if (sum == s) {
cnt++;
}
return;
}
for (i = x; i < 10; i++) {
// if(sum+i>s)return;
func(sum + i, depth + 1, i + 1);
}
}
int main(void) {
while (scanf("%d %d", &n, &s), n || s) {
cnt = 0;
func(0, 1, 0);
printf("%d\n", cnt);
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
| 0
| 133
| 2
|
// 2019/05/02 Tazoe
#include <iostream>
using namespace std;
int cnt;
void DFS(int n, int s, int m) {
if (n == 0 && s == 0) {
cnt++;
return;
}
if (n <= 0)
return;
if (s <= 0)
return;
if (m > 9)
return;
DFS(n - 1, s - m, m + 1);
DFS(n, s, m + 1);
return;
}
int main() {
while (true) {
int n, s;
cin >> n >> s;
if (n == 0 && s == 0)
break;
cnt = 0;
DFS(n, s, 0);
cout << cnt << endl;
}
return 0;
}
|
// 2019/05/02 Tazoe
#include <iostream>
using namespace std;
int cnt;
void DFS(int n, int s, int m) {
if (n == 0 && s == 0) {
cnt++;
return;
}
if (n <= 0)
return;
if (s < 0)
return;
if (m > 9)
return;
DFS(n - 1, s - m, m + 1);
DFS(n, s, m + 1);
return;
}
int main() {
while (true) {
int n, s;
cin >> n >> s;
if (n == 0 && s == 0)
break;
cnt = 0;
DFS(n, s, 0);
cout << cnt << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 150
| 2
|
#include <iostream>
using namespace std;
int n, s;
int dfs(int a, int m, int c) {
if (a == s && c == n)
return 1;
if (a >= s || c >= n)
return 0;
if (m > 9)
return 0;
int t = 0;
for (int i = m; a + i <= s && i < 10; i++) {
t += dfs(a + i, i + 1, c + 1);
}
return t;
}
int main() {
while (true) {
cin >> n >> s;
if (n == 0 && s == 0)
break;
cout << dfs(0, 0, 0) << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int n, s;
int dfs(int a, int m, int c) {
if (a == s && c == n)
return 1;
if (a > s || c > n)
return 0;
if (m > 9)
return 0;
int t = 0;
for (int i = m; a + i <= s && i < 10; i++) {
t += dfs(a + i, i + 1, c + 1);
}
return t;
}
int main() {
while (true) {
cin >> n >> s;
if (n == 0 && s == 0)
break;
cout << dfs(0, 0, 0) << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 47], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47]]
| 1
| 153
| 4
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int test(int n, int s, int i) { // n個でsを作る
// cout << n <<" "<<s<<" "<<i<<endl;
if (n == 0) {
if (s == 0) {
return 1; //作れた
} else {
return 0;
}
}
if (s - i < 0) {
return 0;
}
return test(n, s, i + 1) + test(n - 1, s - i, i + 1);
}
int main() {
int km[11][101] = {0};
for (int i = 0; i < 10; i++) {
km[1][i] = 1;
}
/*
for(int i=1;i<9;i++){
for(int j=i-1;j<101;j++){
for(int k=j;j+k<101;k++){
if(i+1==3 && j+k==6) cout << i << " "<< j<<" "<<k<<"
"<<km[i][j]<<endl; if(j!=k){ km[i+1][j+k]+=km[i][j]; }else{ km[i+1][j+k]+=1;
}
}
}
}
*/
/*
for(int i=2;i<=10;i++){
/*
for(int j=0;j<101;j++){
if(km[i-1][j]){
for(int k=j+1;k<=10&&j+k<101;k++){
if(i==3 && j+k==6) cout << j<<" "<<k<<endl;
km[i][j+k]+=km[i-1][j];
}
}
}
for(int j=0;j<10;j++){
for(int k=0;k<101;k++){
if(km[i-1][k]&&k>j){
if(i==3 && k+j==1) cout << j<<" "<<k<<endl;;
km[i][k+j]++;
}
}
}
}
*/
/*
for(int i=2;i<=10;i++){//2個で作る組み合わせから計算
for(int j=0;j<101;j++){//横に調べて行って
if(km[i-1][j]){//もしあれば
for(int k=i-1;k<10;k++){
if(i==2 && k+j==3) cout << j<<" "<<k<<endl;
km[i][j+k]++;
}
}
}
}
for(int i=0;i<10;i++){
for(int j=0;j<30;j++){
cout << km[i][j]<<" ";
}
cout << endl;
}
cout << km[3][6];
*/
/*
int n, s;
while(cin >> n >> s){
if(n==0 && s==0) break;
cout << km[n][s] << endl;
}
*/
int n, s;
while (cin >> n >> s) {
if (n == 0 && s == 0)
break;
cout << test(n, s, 0) << endl;
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int test(int n, int s, int i) { // n個でsを作る
// cout << n <<" "<<s<<" "<<i<<endl;
if (n == 0) {
if (s == 0) {
return 1; //作れた
} else {
return 0;
}
}
if (i >= 10 || s - i < 0) {
return 0;
}
return test(n, s, i + 1) + test(n - 1, s - i, i + 1);
}
int main() {
int km[11][101] = {0};
for (int i = 0; i < 10; i++) {
km[1][i] = 1;
}
/*
for(int i=1;i<9;i++){
for(int j=i-1;j<101;j++){
for(int k=j;j+k<101;k++){
if(i+1==3 && j+k==6) cout << i << " "<< j<<" "<<k<<"
"<<km[i][j]<<endl; if(j!=k){ km[i+1][j+k]+=km[i][j]; }else{ km[i+1][j+k]+=1;
}
}
}
}
*/
/*
for(int i=2;i<=10;i++){
/*
for(int j=0;j<101;j++){
if(km[i-1][j]){
for(int k=j+1;k<=10&&j+k<101;k++){
if(i==3 && j+k==6) cout << j<<" "<<k<<endl;
km[i][j+k]+=km[i-1][j];
}
}
}
for(int j=0;j<10;j++){
for(int k=0;k<101;k++){
if(km[i-1][k]&&k>j){
if(i==3 && k+j==1) cout << j<<" "<<k<<endl;;
km[i][k+j]++;
}
}
}
}
*/
/*
for(int i=2;i<=10;i++){//2個で作る組み合わせから計算
for(int j=0;j<101;j++){//横に調べて行って
if(km[i-1][j]){//もしあれば
for(int k=i-1;k<10;k++){
if(i==2 && k+j==3) cout << j<<" "<<k<<endl;
km[i][j+k]++;
}
}
}
}
for(int i=0;i<10;i++){
for(int j=0;j<30;j++){
cout << km[i][j]<<" ";
}
cout << endl;
}
cout << km[3][6];
*/
/*
int n, s;
while(cin >> n >> s){
if(n==0 && s==0) break;
cout << km[n][s] << endl;
}
*/
int n, s;
while (cin >> n >> s) {
if (n == 0 && s == 0)
break;
cout << test(n, s, 0) << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106]]
| 1
| 192
| 4
|
#define _CRT_SECURE_NO_WARNINGS
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <stack>
#include <string>
using namespace std;
int n = 0;
int s = 0;
static int ans;
void check(int atai, int num, int count) {
if (num > 9) {
if (atai == s && count == n) {
ans++;
}
return;
}
check(atai + num, num + 1, count + 1);
check(atai, num + 1, count);
}
int main(int argc, char **argv) {
while (cin >> n >> s) {
if (n == 0 && s == 0) {
break;
}
check(0, 0, 0);
cout << ans << endl;
}
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <stack>
#include <string>
using namespace std;
int n = 0;
int s = 0;
static int ans;
void check(int atai, int num, int count) {
if (num > 9) {
if (atai == s && count == n) {
ans++;
}
return;
}
check(atai + num, num + 1, count + 1);
check(atai, num + 1, count);
}
int main(int argc, char **argv) {
while (cin >> n >> s) {
ans = 0;
if (n == 0 && s == 0) {
break;
}
check(0, 0, 0);
cout << ans << endl;
}
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 149
| 4
|
#include <cstdio>
#include <iostream>
using namespace std;
int n, s, count;
int solve(int i, int sum, int used) {
if (i == 10) {
if (s == sum && used == n) {
return count + 1;
}
return count;
}
solve(i + 1, sum + i, used + 1);
solve(i + 1, sum, used);
return count;
}
int main() {
while (cin >> n >> s, n) {
count = 0;
cout << solve(0, 0, 0) << endl;
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int n, s, count;
int solve(int i, int sum, int used) {
if (i == 10) {
if (s == sum && used == n) {
count++;
}
return count;
}
solve(i + 1, sum + i, used + 1);
solve(i + 1, sum, used);
return count;
}
int main() {
while (cin >> n >> s, n || s) {
count = 0;
cout << solve(0, 0, 0) << endl;
}
return 0;
}
|
[["-", 64, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["-", 0, 57, 64, 9, 0, 37, 0, 16, 17, 72], ["-", 0, 57, 64, 9, 0, 37, 0, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 27, 17, 29], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 12, 22]]
| 1
| 124
| 6
|
#include <iostream>
using namespace std;
int n, s, cnt;
void dfs(int m, int num, int sum);
int main() {
while (cin >> n >> s, n && s) {
cnt = 0;
dfs(1, 0, 0);
cout << cnt << endl;
}
return 0;
}
void dfs(int m, int num, int sum) {
if (m > 9 && (num == n || num == n - 1) && sum == s)
cnt++;
if (m > 9)
return;
dfs(m + 1, num + 1, sum + m);
dfs(m + 1, num, sum);
}
|
#include <iostream>
using namespace std;
int n, s, cnt;
void dfs(int m, int num, int sum);
int main() {
while (cin >> n >> s, n || s) {
cnt = 0;
dfs(1, 0, 0);
cout << cnt << endl;
}
return 0;
}
void dfs(int m, int num, int sum) {
if (m > 9 && (num == n || num == n - 1) && sum == s)
cnt++;
if (m > 9)
return;
dfs(m + 1, num + 1, sum + m);
dfs(m + 1, num, sum);
}
|
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
| 1
| 141
| 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 n, s;
vector<int> flags;
while (cin >> n >> s) {
if (n == 0 && s == 0) {
break;
}
flags.clear();
for (int i = 0; i < 9; i++) {
flags.push_back(i < n ? 1 : 0);
}
sort(flags.begin(), flags.end());
int count = 0;
do {
int sum = 0;
for (unsigned int i = 0; i < flags.size(); i++) {
if (flags[i]) {
sum += i;
}
}
if (s == sum) {
count++;
}
} while (next_permutation(flags.begin(), flags.end()));
cout << count << endl;
}
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 n, s;
vector<int> flags;
while (cin >> n >> s) {
if (n == 0 && s == 0) {
break;
}
flags.clear();
for (int i = 0; i < 10; i++) {
flags.push_back(i < n ? 1 : 0);
}
sort(flags.begin(), flags.end());
int count = 0;
do {
int sum = 0;
for (unsigned int i = 0; i < flags.size(); i++) {
if (flags[i]) {
sum += i;
}
}
if (s == sum) {
count++;
}
} while (next_permutation(flags.begin(), flags.end()));
cout << count << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 208
| 2
|
#include <iostream>
#include <vector>
using namespace std;
int t;
int num[10];
void sousa(int a, int b) {
for (num[a - 1] = num[a] - 1; num[a - 1] >= 0; num[a - 1]--) {
if (a - 1 < 0 || b < 0) {
break;
} else if (a - 1 == 0 && b - num[a - 1] == 0) {
t++;
break;
} else {
sousa(a - 1, b - num[a - 1]);
}
}
}
int main() {
vector<int> array;
int n, m;
while (cin >> n >> m) {
if (n == 0 && m == 0) {
break;
}
if (m > 45) {
array.push_back(0);
continue;
}
t = 0;
num[n] = 9;
sousa(n, m);
array.push_back(t);
}
for (int i = 0; i < array.size(); i++) {
cout << array[i] << endl;
}
}
|
#include <iostream>
#include <vector>
using namespace std;
int t;
int num[10];
void sousa(int a, int b) {
for (num[a - 1] = num[a] - 1; num[a - 1] >= 0; num[a - 1]--) {
if (a - 1 < 0 || b < 0) {
break;
} else if (a - 1 == 0 && b - num[a - 1] == 0) {
t++;
break;
} else {
sousa(a - 1, b - num[a - 1]);
}
}
}
int main() {
vector<int> array;
int n, m;
while (cin >> n >> m) {
if (n == 0 && m == 0) {
break;
}
if (m > 45) {
array.push_back(0);
continue;
}
t = 0;
num[n] = 10;
sousa(n, m);
array.push_back(t);
}
for (int i = 0; i < array.size(); i++) {
cout << array[i] << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
| 1
| 237
| 2
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
//#define PI 3.141592653589
using namespace std;
int ans;
int n, s;
/*
iはこれまでに足し合わせた数字の数
*/
void dfs(int i, int kazu, int sum) {
if (i == n && sum == s) {
ans++;
return;
} else if (i == n) {
return;
} else if (kazu == 9) {
return;
}
dfs(i, kazu + 1, sum);
dfs(i + 1, kazu + 1, sum + kazu);
}
int main() {
while (1) {
cin >> n >> s;
if (n == 0 && s == 0)
break;
ans = 0;
dfs(0, 0, 0);
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
//#define PI 3.141592653589
using namespace std;
int ans;
int n, s;
/*
iはこれまでに足し合わせた数字の数
*/
void dfs(int i, int kazu, int sum) {
if (i == n && sum == s) {
ans++;
return;
} else if (i == n) {
return;
} else if (kazu == 10) {
return;
}
dfs(i, kazu + 1, sum);
dfs(i + 1, kazu + 1, sum + kazu);
}
int main() {
while (1) {
cin >> n >> s;
if (n == 0 && s == 0)
break;
ans = 0;
dfs(0, 0, 0);
cout << ans << endl;
}
return 0;
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 159
| 2
|
#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;
#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 ans;
int a, b;
void solve(int i, int _b, int sum) {
if (sum == a && _b == 0) {
ans++;
return;
}
if (_b == 0 || i == 10)
return;
if (i != -1)
solve(i + 1, _b - 1, sum + i);
solve(i + 1, _b, sum);
}
int main() {
while (cin >> b >> a, a && b) {
ans = 0;
solve(-1, b, 0);
cout << ans << 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;
#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 ans;
int a, b;
void solve(int i, int _b, int sum) {
if (sum == a && _b == 0) {
ans++;
return;
}
if (_b == 0 || i == 10)
return;
if (i != -1)
solve(i + 1, _b - 1, sum + i);
solve(i + 1, _b, sum);
}
int main() {
while (cin >> b >> a, a || b) {
ans = 0;
solve(-1, b, 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
| 174
| 2
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;
const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(c) (c).begin(), (c).end()
struct edge {
int to, cost;
edge(int t, int c) : to(t), cost(c) {}
};
int main() {
// while (cin >> n)
stringstream ss;
// ss << "result" << i + 1 << ".txt";
// FILE* fp_out = freopen(ss.str().c_str(), "w", stdout);
int n;
while (cin >> n) {
int s;
cin >> s;
function<int(int, int, int)> dfs = [&](int now, int rem, int sum) {
if (rem == 0 && sum == s)
return 1;
if (now == 10 || rem == 0 || sum > s)
return 0;
return dfs(now + 1, rem, sum) + dfs(now + 1, rem - 1, sum + now);
};
cout << dfs(0, n, 0) << endl;
}
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;
const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(c) (c).begin(), (c).end()
struct edge {
int to, cost;
edge(int t, int c) : to(t), cost(c) {}
};
int main() {
// while (cin >> n)
stringstream ss;
// ss << "result" << i + 1 << ".txt";
// FILE* fp_out = freopen(ss.str().c_str(), "w", stdout);
int n;
while (cin >> n && n) {
int s;
cin >> s;
function<int(int, int, int)> dfs = [&](int now, int rem, int sum) {
if (rem == 0 && sum == s)
return 1;
if (now == 10 || rem == 0 || sum > s)
return 0;
return dfs(now + 1, rem, sum) + dfs(now + 1, rem - 1, sum + now);
};
cout << dfs(0, n, 0) << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
| 1
| 253
| 2
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//????????????
// test?????£???wrong answer????????£??????
int n, s;
int c;
void search(int a, int sum, int before) {
FOR(i, before, 9) {
if (sum + i > s)
continue;
if (a < n)
search(a + 1, sum + i, i + 1);
else if (sum + i == s) {
// cout << i <<" " << sum << " " << before-1 << endl;
c++;
}
}
}
int main() {
while (1) {
cin >> n >> s;
c = 0;
if (n == 0 && s == 0)
break;
search(1, 0, 0);
cout << c << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//????????????
// test?????£???wrong answer????????£??????
int n, s;
int c;
void search(int a, int sum, int before) {
FOR(i, before, 10) {
if (sum + i > s)
continue;
if (a < n)
search(a + 1, sum + i, i + 1);
else if (sum + i == s) {
// cout << i <<" " << sum << " " << before-1 << endl;
c++;
}
}
}
int main() {
while (1) {
cin >> n >> s;
c = 0;
if (n == 0 && s == 0)
break;
search(1, 0, 0);
cout << c << endl;
}
}
|
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
| 1
| 255
| 2
|
#include <algorithm>
#include <iostream>
using namespace std;
int func(int num, int rest, int before) {
// if(before + 1 < 0) return 0;
if (num == 0) {
if (rest == 0) {
// cout << before << endl;
return 1;
}
return 0;
}
int res = 0;
for (int i = 0; i <= rest && i <= before; ++i) {
res += func(num - 1, rest - i, i - 1);
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, s;
while (cin >> n >> s && n != 0 && s != 0) {
cout << func(n, s, 9) << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int func(int num, int rest, int before) {
// if(before + 1 < 0) return 0;
if (num == 0) {
if (rest == 0) {
// cout << before << endl;
return 1;
}
return 0;
}
int res = 0;
for (int i = 0; i <= rest && i <= before; ++i) {
res += func(num - 1, rest - i, i - 1);
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, s;
while (cin >> n >> s && (n != 0 || s != 0)) {
cout << func(n, s, 9) << 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
| 150
| 4
|
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
long long int saiki(int N, int M, int O) {
if (N == 1) {
return M > O;
}
long long int ans = 0;
for (int i = O + 1; i <= min(9, M); i++) {
ans += saiki(N - 1, M - i, i);
}
return ans;
}
int main() {
int N, M;
while (cin >> N >> M, N || M) {
cout << saiki(N, M, -1) << endl;
}
}
|
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
long long int saiki(int N, int M, int O) {
if (N == 1) {
return M > O && M <= 9;
}
long long int ans = 0;
for (int i = O + 1; i <= min(9, M); i++) {
ans += saiki(N - 1, M - i, i);
}
return ans;
}
int main() {
int N, M;
while (cin >> N >> M, N || M) {
cout << saiki(N, M, -1) << endl;
}
}
|
[["+", 0, 57, 64, 9, 0, 37, 0, 16, 17, 98], ["+", 64, 9, 0, 37, 0, 16, 12, 16, 31, 22], ["+", 64, 9, 0, 37, 0, 16, 12, 16, 17, 19], ["+", 64, 9, 0, 37, 0, 16, 12, 16, 12, 13]]
| 1
| 276
| 4
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
using namespace std;
int n, s;
int solve(int now, int last, int count) {
if (count == n && now == s) {
return 1;
}
if (count == n || now > s) {
return 0;
}
int co = 0;
for (int i = last + 1; i < 10; i++) {
co += solve(now + i, i, count + 1);
}
return co;
}
int main() {
while (cin >> n >> s) {
if (n == 0 && s == 0)
break;
int count = 0;
for (int i = 0; i < n; i++) {
count += solve(i, i, 1);
}
cout << count << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
using namespace std;
int n, s;
int solve(int now, int last, int count) {
if (count == n && now == s) {
return 1;
}
if (count == n || now > s) {
return 0;
}
int co = 0;
for (int i = last + 1; i < 10; i++) {
co += solve(now + i, i, count + 1);
}
return co;
}
int main() {
while (cin >> n >> s) {
if (n == 0 && s == 0)
break;
int count = 0;
for (int i = 0; i < 10; i++) {
count += solve(i, i, 1);
}
cout << count << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 173
| 2
|
#include <iostream>
#define N 9
using namespace std;
int solver(int n, int s,
int t) { // t??\????????°n?????§s?????????????????????????????°
if (n == 0 || s < 0 || t > N)
return 0;
if (n == 1 && s == t)
return 1;
return solver(n - 1, s - t, t + 1) + solver(n, s, t + 1);
}
int main() {
int n, s;
while (cin >> n >> s, n) {
cout << solver(n, s, 0);
}
return 0;
}
|
#include <iostream>
#define N 9
using namespace std;
int solver(int n, int s,
int t) { // t??\????????°n?????§s?????????????????????????????°
if (n == 0 || s < 0 || t > N)
return 0;
if (n == 1 && s == t)
return 1;
return solver(n - 1, s - t, t + 1) + solver(n, s, t + 1);
}
int main() {
int n, s;
while (cin >> n >> s, n) {
cout << solver(n, s, 0) << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 118
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, l, n) for (lint i = l; i < n; i++)
#define rer(i, l, n) for (lint i = l; i <= n; i++)
#define alint(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
lint n, s, ans = 0;
void solve(lint n, lint sum, lint max) {
if (n) {
rep(i, max + 1, 9) { solve(n - 1, sum + i, i); }
} else if (sum == s) {
ans++;
return;
}
return;
}
int main() {
while (1) {
cin >> n >> s;
if (n == 0 && s == 0)
break;
ans = 0;
solve(n, 0, -1);
o(ans);
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, l, n) for (lint i = l; i < n; i++)
#define rer(i, l, n) for (lint i = l; i <= n; i++)
#define alint(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
lint n, s, ans = 0;
void solve(lint n, lint sum, lint max) {
if (n) {
rep(i, max + 1, 10) { solve(n - 1, sum + i, i); }
} else if (sum == s) {
ans++;
return;
}
return;
}
int main() {
while (1) {
cin >> n >> s;
if (n == 0 && s == 0)
break;
ans = 0;
solve(n, 0, -1);
o(ans);
}
}
|
[["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
| 1
| 228
| 2
|
#include <bits/stdc++.h>
using namespace std;
int dfs(int n, int s, int i) {
if (n == 0) {
if (s == 0)
return 1;
else
return 0;
}
if (s <= 0)
return 0;
if (i > 9)
return 0;
return dfs(n, s, i + 1) + dfs(n - 1, s - i, i + 1);
}
int main() {
int n, s;
while (cin >> n >> s, n | s) {
cout << dfs(n, s, 0) << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int dfs(int n, int s, int i) {
if (n == 0) {
if (s == 0)
return 1;
else
return 0;
}
if (s - i < 0)
return 0;
if (i > 9)
return 0;
return dfs(n, s, i + 1) + dfs(n - 1, s - i, i + 1);
}
int main() {
int n, s;
while (cin >> n >> s, n | s) {
cout << dfs(n, s, 0) << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 124
| 4
|
#include <iostream>
using namespace std;
int n, s;
int dfs(int i, int sum, int N) {
if (N == 0 && sum == 0)
return 1; // yes
if (N == 0 || i == 10)
return 0; // no
return dfs(i + 1, sum, N) + dfs(i + 1, sum - i, N - 1);
}
int main() {
while (cin >> n >> s, s) {
cout << dfs(0, s, n) << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int n, s;
int dfs(int i, int sum, int N) {
if (N == 0 && sum == 0)
return 1; // yes
if (N == 0 || i == 10)
return 0; // no
return dfs(i + 1, sum, N) + dfs(i + 1, sum - i, N - 1);
}
int main() {
while (cin >> n >> s, n) {
cout << dfs(0, s, n) << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
| 1
| 114
| 16
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
long long int fie[110][11][1100];
int main() {
while (1) {
memset(fie, 0, sizeof(fie));
int N, S;
cin >> N >> S;
if (N == 0 && S == 0)
break;
fie[1][0][0] = 1;
fie[1][1][1] = 1;
for (int i = 1; i < 100; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k <= 1000; k++) {
fie[i + 1][j][k] += fie[i][j][k];
fie[i + 1][j + 1][k + i + 1] += fie[i][j][k];
}
}
}
cout << fie[100][N][S] + fie[100][N - 1][S] << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
long long int fie[110][11][1100];
int main() {
while (1) {
memset(fie, 0, sizeof(fie));
int N, S;
cin >> N >> S;
if (N == 0 && S == 0)
break;
fie[1][0][0] = 1;
fie[1][1][1] = 1;
for (int i = 1; i < 9; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k <= 1000; k++) {
fie[i + 1][j][k] += fie[i][j][k];
fie[i + 1][j + 1][k + i + 1] += fie[i][j][k];
}
}
}
cout << fie[9][N][S] + fie[9][N - 1][S] << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 31, 69, 28, 69, 28, 69, 341, 342, 0, 13], ["+", 31, 69, 28, 69, 28, 69, 341, 342, 0, 13], ["-", 12, 69, 28, 69, 28, 69, 341, 342, 0, 13], ["+", 12, 69, 28, 69, 28, 69, 341, 342, 0, 13]]
| 1
| 234
| 6
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
/*
0 1 2 3 4 5 6 7 8 9
*/
// int a(int n, int s, int f) {
// int cnt = 0;
// if (n > 2)
// for (int i = f; i <= 9; i++) {
// if (s - i > i)cnt += a(n - 1, s - i, i + 1);
// else break;
// }
// else if (n == 2)
// for (int i = f; i <= 9; i++) {
// if (s - i <= 9 && s - i > i)cnt++;
// else break;
// }
// else
// cnt = 1;
//
// return cnt;
//}
int a = 0, S;
void dfs(int i, int s, int n) {
// cout << i << " " << s << " " << n << endl;
if (s == S && n == 0) {
a++;
return;
}
if (i == 10 || n == 0)
return;
dfs(i + 1, s + i, n - 1);
dfs(i + 1, s, n);
}
int main() {
for (int n; cin >> n >> S && (n || S);) {
dfs(0, 0, n);
cout << a << endl;
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int a, S;
void dfs(int i, int s, int n) {
if (s == S && n == 0) {
a++;
return;
}
if (i == 10 || n == 0)
return;
dfs(i + 1, s + i, n - 1);
dfs(i + 1, s, n);
}
int main() {
for (int n; cin >> n >> S && (n || S);) {
a = 0;
dfs(0, 0, n);
cout << a << endl;
}
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 0, 32], ["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
| 1
| 175
| 6
|
#include <iostream>
using namespace std;
int ans = 0;
void dfs(int n, int s, int d) {
if (s < 0)
return;
if (s == 0 and n == 0) {
ans++;
return;
}
if (n == 0)
return;
d++;
if (d == 10)
return;
// cout << "n=" << n;
// cout << " s=" << s;
// cout << " d=" << d << endl;
//???????????´???
dfs(n - 1, s - d, d);
//?????°????????£?????´???
dfs(n, s, d);
return;
}
int main() {
int n, s;
cin >> n >> s;
while (!(n == 0 and s == 0)) {
dfs(n, s, -1);
cout << ans << endl;
cin >> n >> s;
}
return 0;
}
|
#include <iostream>
using namespace std;
int ans = 0;
void dfs(int n, int s, int d) {
if (s < 0)
return;
if (s == 0 and n == 0) {
ans++;
return;
}
if (n == 0)
return;
d++;
if (d == 10)
return;
//???????????´???
dfs(n - 1, s - d, d);
//?????°????????£?????´???
dfs(n, s, d);
return;
}
int main() {
int n, s;
cin >> n >> s;
while (!(n == 0 and s == 0)) {
dfs(n, s, -1);
cout << ans << endl;
ans = 0;
cin >> n >> s;
}
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
| 154
| 4
|
#include <bits/stdc++.h>
using namespace std;
int dfs(int x, int y, int k) {
if (y == 0)
return x == 0 ? 1 : 0;
if (x < 0)
return 0;
int ans = 0;
for (int i = k + 1; i < 10; i++)
ans += dfs(x - i, y - 1, i);
return ans;
}
signed main(void) {
ios::sync_with_stdio(false);
int x, y;
while (cin >> y >> x && (x || y))
cout << dfs(x, y, -1);
}
|
#include <bits/stdc++.h>
using namespace std;
int dfs(int x, int y, int k) {
if (y == 0)
return x == 0 ? 1 : 0;
if (x < 0)
return 0;
int ans = 0;
for (int i = k + 1; i < 10; i++)
ans += dfs(x - i, y - 1, i);
return ans;
}
signed main(void) {
ios::sync_with_stdio(false);
int x, y;
while (cin >> y >> x && (x || y))
cout << dfs(x, y, -1) << endl;
}
|
[["+", 8, 9, 0, 52, 8, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 52, 8, 1, 0, 16, 12, 22]]
| 1
| 127
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int A[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int cunt = 0;
void depth(int n, int s, int i) {
if (n == 0 && s == 0) {
cunt++;
return;
} else if (n == 0)
return;
else if (s == 0)
return;
else if (i == 10)
return;
depth(n - 1, s - A[i], i++);
depth(n, s, i++);
}
int main() {
int n, s;
while (cin >> n >> s) {
if (n == 0 && s == 0)
break;
depth(n, s, 0);
cout << cunt << endl;
cunt = 0;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int A[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int cunt = 0;
void depth(int n, int s, int i) {
if (n == 0 && s == 0) {
cunt++;
return;
} else if (n == 0)
return;
else if (s < 0)
return;
else if (i == 10)
return;
depth(n - 1, s - A[i], i + 1);
depth(n, s, i + 1);
}
int main() {
int n, s;
while (cin >> n >> s) {
if (n == 0 && s == 0)
break;
depth(n, s, 0);
cout << cunt << endl;
cunt = 0;
}
return 0;
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 0, 1, 0, 2, 3, 4, 0, 27, 17, 29], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 193
| 8
|
#include <iostream>
using namespace std;
int n, s, ans;
void solve(int v, int sum, int num) {
if (sum == s && num == n) {
ans++;
return;
}
if (v >= 10 || sum >= s)
return;
solve(v + 1, sum + v, num + 1);
solve(v + 1, sum, num);
}
int main() {
while (1) {
cin >> n >> s;
if (n == 0 && s == 0)
break;
ans = 0;
solve(0, 0, 0);
cout << ans << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int n, s, ans;
void solve(int v, int sum, int num) {
if (sum == s && num == n) {
ans++;
return;
}
if (v >= 10 || num >= n)
return;
solve(v + 1, sum + v, num + 1);
solve(v + 1, sum, num);
}
int main() {
while (1) {
cin >> n >> s;
if (n == 0 && s == 0)
break;
ans = 0;
solve(0, 0, 0);
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
| 1
| 134
| 4
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define shosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const double pi = acos(-1);
int n, s, ans;
void func(int x, int y, int z) {
if (!x && !y) {
ans++;
return;
}
if (!x || y <= 0 || z == 10)
return;
for (int i = z; i < 10; i++)
func(x - 1, y - i, i + 1);
}
int main() {
while (1) {
cin >> n >> s;
if (!n && !s)
break;
ans = 0;
func(n, s, 0);
cout << ans << endl;
}
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define shosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const double pi = acos(-1);
int n, s, ans;
void func(int x, int y, int z) {
if (!x && !y) {
ans++;
return;
}
if (!x || y < 0 || z == 10)
return;
for (int i = z; i < 10; i++)
func(x - 1, y - i, i + 1);
}
int main() {
while (1) {
cin >> n >> s;
if (!n && !s)
break;
ans = 0;
func(n, s, 0);
cout << ans << endl;
}
}
|
[["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 19], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 18]]
| 1
| 230
| 2
|
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
int c = 0;
string s, large = "", max;
map<string, int> wordbox;
while (cin >> s) {
wordbox[s]++;
if (s.length() > large.length())
large = s;
}
map<string, int>::iterator it = wordbox.begin();
while (it != wordbox.end()) {
if ((*it).second > c)
max = (*it).first, c = (*it).second;
it++;
}
cout << large << " " << max << endl;
return 0;
}
|
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
int c = 0;
string s, large = "", max;
map<string, int> wordbox;
while (cin >> s) {
wordbox[s]++;
if (s.length() > large.length())
large = s;
}
map<string, int>::iterator it = wordbox.begin();
while (it != wordbox.end()) {
if ((*it).second > c)
max = (*it).first, c = (*it).second;
it++;
}
cout << max << " " << large << endl;
return 0;
}
|
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 146
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
map<string, int> count;
int m = 0;
string first;
string second("");
while (!cin.eof()) {
string s;
cin >> s;
if (count.count(s) == 0)
count.insert(make_pair(s, 1));
else
count.find(s)->second++;
if (count.find(s)->second > m) {
first = s;
m = count.find(s)->second;
}
if (s.size() > second.size())
second = s;
}
cout << first << second << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
map<string, int> count;
int m = 0;
string first;
string second("");
while (!cin.eof()) {
string s;
cin >> s;
if (count.count(s) == 0)
count.insert(make_pair(s, 1));
else
count.find(s)->second++;
if (count.find(s)->second > m) {
first = s;
m = count.find(s)->second;
}
if (s.size() > second.size())
second = s;
}
cout << first << " " << second << endl;
return 0;
}
|
[["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151]]
| 1
| 164
| 4
|
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
string s, max("");
map<string, int> w;
map<int, string> x;
while (cin >> s) {
if (s.size() > max.size())
max = s;
w[s]++;
}
for (map<string, int>::iterator it = w.begin(); it != w.end(); it++)
x[(*it).second] = (*it).first;
cout << (*x.rbegin()).second
<< ""
""
<< max << endl;
return 0;
}
|
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
string s, max("");
map<string, int> w;
map<int, string> x;
while (cin >> s) {
if (s.size() > max.size())
max = s;
w[s]++;
}
for (map<string, int>::iterator it = w.begin(); it != w.end(); it++)
x[(*it).second] = (*it).first;
cout << (*x.rbegin()).second << " " << max << endl;
return 0;
}
|
[["-", 31, 16, 31, 16, 12, 61, 0, 5, 0, 62], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 144
| 3
|
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
string str, s, mls, mcs, input[32];
map<string, int> dic;
int n, c, a, ml, mc;
getline(cin, str);
c = a = mc = ml = 0;
str += ' ';
while (str.length()) {
n = str.find(' ');
s = str[c];
++c;
for (; c < n; ++c) {
s += str[c];
}
str.erase(0, n + 1);
c = 0;
input[a] = s;
++a;
++dic[s];
if (s.length() > ml) {
ml = s.length();
mls = s;
}
}
for (int i = 0; i < a; ++i) {
if (mc < dic[input[i]]) {
mc = dic[input[i]];
mcs = input[i];
}
cout << mcs << " " << mls << endl;
}
return 0;
}
|
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
string str, s, mls, mcs, input[100];
map<string, int> dic;
int n, c, a, ml, mc;
getline(cin, str);
c = a = mc = ml = 0;
str += ' ';
while (str.length()) {
n = str.find(' ');
s = str[c];
++c;
for (; c < n; ++c) {
s += str[c];
}
str.erase(0, n + 1);
c = 0;
input[a] = s;
++a;
++dic[s];
if (s.length() > ml) {
ml = s.length();
mls = s;
}
}
for (int i = 0; i < a; ++i) {
if (mc < dic[input[i]]) {
mc = dic[input[i]];
mcs = input[i];
}
}
cout << mcs << " " << mls << endl;
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46]]
| 1
| 239
| 4
|
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
string sp, st, hw, ew;
map<string, int> sd;
int s = 0, e = 0, k = 0, h = 0, m = 0;
getline(cin, st);
st = st + " ";
while (e != st.size()) {
for (e; st[e] != ' '; e++)
;
sp.append(st, s, e - s);
if (sp.length() > h) {
h = sp.length();
hw = sp;
}
if (sd.find(sp) == sd.end())
sd.insert(map<string, int>::value_type(sp, 1));
else {
sd[sp]++;
if (sd[sp] > m)
m = sd[sp];
}
e++;
s = e;
sp = "";
}
map<string, int>::iterator it = sd.begin();
for (h = 0; it != sd.end(); it++)
if (h < (*it).second) {
h = (*it).second;
ew = (*it).first;
}
cout << ew << endl << hw << endl;
return 0;
}
|
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
string sp, st, hw, ew;
map<string, int> sd;
int s = 0, e = 0, k = 0, h = 0, m = 0;
getline(cin, st);
st = st + " ";
while (e != st.size()) {
for (e; st[e] != ' '; e++)
;
sp.append(st, s, e - s);
if (sp.length() > h) {
h = sp.length();
hw = sp;
}
if (sd.find(sp) == sd.end())
sd.insert(map<string, int>::value_type(sp, 1));
else {
sd[sp]++;
if (sd[sp] > m)
m = sd[sp];
}
e++;
s = e;
sp = "";
}
map<string, int>::iterator it = sd.begin();
for (h = 0; it != sd.end(); it++)
if (h < (*it).second) {
h = (*it).second;
ew = (*it).first;
}
cout << ew << " " << hw << endl;
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 285
| 4
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
string s;
map<string, int> m;
map<string, int> m2;
int maxlen = -1;
pair<string, int> max_pair;
pair<string, int> max2_pair;
while (cin >> s) {
if (m.count(s) == 0) {
m.insert(pair<string, int>(s, 0));
m2.insert(pair<string, int>(s, (int)s.length()));
} else {
m[s]++;
}
}
for (auto pm = m.begin(); pm != m.end(); pm++) {
if (pm->second > max_pair.second) {
max_pair = *pm;
}
}
for (auto pm = m2.begin(); pm != m2.end(); pm++) {
if (pm->second > max2_pair.second) {
max2_pair = *pm;
}
}
cout << max_pair.first << endl << max2_pair.first << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
string s;
map<string, int> m;
map<string, int> m2;
int maxlen = -1;
pair<string, int> max_pair;
pair<string, int> max2_pair;
while (cin >> s) {
if (m.count(s) == 0) {
m.insert(pair<string, int>(s, 0));
m2.insert(pair<string, int>(s, (int)s.length()));
} else {
m[s]++;
}
}
for (auto pm = m.begin(); pm != m.end(); pm++) {
if (pm->second > max_pair.second) {
max_pair = *pm;
}
}
for (auto pm = m2.begin(); pm != m2.end(); pm++) {
if (pm->second > max2_pair.second) {
max2_pair = *pm;
}
}
cout << max_pair.first << " " << max2_pair.first << endl;
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 228
| 4
|
strings = gets.split(" ")
hash = Hash.new(0)
longest_size = strings.max_by{ |(elm1)| elm1.length}
strings.each {|e| hash[e] += 1}
freq_num = hash.max_by{|_,len_i| len_i }[1]
puts "#{freq_num} #{longest_size}"
|
strings = gets.split(" ")
hash = Hash.new(0)
longest_size = strings.max_by{ |(elm1)| elm1.length}
strings.each {|e| hash[e] += 1}
freq_num = hash.max_by{|_,len_i| len_i }[0]
puts "#{freq_num} #{longest_size}"
|
[["-", 36, 36, 0, 493, 0, 662, 12, 742, 0, 612], ["+", 36, 36, 0, 493, 0, 662, 12, 742, 0, 612]]
| 4
| 73
| 2
|
words = gets.split.group_by{|i| i}
puts "#{words.max_by{|k,v| v}.first} #{words.keys.max_by{|i| i.size}}"
|
words = gets.split.group_by{|i| i}
puts "#{words.max_by{|k,v| v.size}.first} #{words.keys.max_by{|i| i.size}}"
|
[["+", 486, 652, 196, 196, 8, 734, 0, 652, 17, 131], ["+", 486, 652, 196, 196, 8, 734, 0, 652, 735, 22]]
| 4
| 47
| 2
|
count = Hash.new(0)
longest = ''
$<.each_line do |line|
line.split.each do |word|
count[word] += 1
longest = word if longest.size < word.size
end
end
puts count.max_by(&:last).first
puts longest
|
count = Hash.new(0)
longest = ''
$<.each_line do |line|
line.split.each do |word|
count[word] += 1
longest = word if longest.size < word.size
end
end
puts count.max_by(&:last).first + ' ' << longest
|
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["+", 0, 652, 3, 4, 0, 738, 31, 738, 17, 72], ["+", 3, 4, 0, 738, 31, 738, 12, 557, 0, 62], ["+", 3, 4, 0, 738, 31, 738, 12, 557, 0, 6], ["+", 0, 493, 0, 652, 3, 4, 0, 738, 17, 151]]
| 4
| 59
| 6
|
while True:
try:
ls = input().split()
dic = {}
for word in ls:
dic[word] = dic.get(word,0) + 1
max1 = sorted(list(dic.items()), key=lambda x:x[1], reverse=True)
max2 = ""
for i in ls:
if len(max2) < i:
max2 = i
print(max1[0][0] + " " + max2)
except:
exit()
|
while True:
try:
ls = input().split()
dic = {}
for word in ls:
dic[word] = dic.get(word,0) + 1
max1 = sorted(list(dic.items()), key=lambda x:x[1], reverse=True)
max2 = ""
for i in ls:
if len(max2) < len(i):
max2 = i
print(max1[0][0] + " " + max2)
except:
exit()
|
[["+", 8, 196, 0, 57, 15, 666, 0, 652, 63, 22], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 24], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 25]]
| 5
| 106
| 3
|
import sys
import math
from collections import Counter
l = input().split()
print(l)
c = Counter()
for i in l:
c[i] += 1
cc = c.most_common(1)
ans = l[0]
for i in range(len(l)):
if len(l[i]) > len(ans):
ans = l[i]
print("{0} {1}".format(cc[0][0], ans))
|
import sys
import math
from collections import Counter
l = input().split()
c = Counter()
for i in l:
c[i] += 1
cc = c.most_common(1)
ans = l[0]
for i in range(len(l)):
if len(l[i]) > len(ans):
ans = l[i]
print("{0} {1}".format(cc[0][0], ans))
|
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 101
| 4
|
S = input().split()
maxi = 0
for s in S:
length = len(s)
if (length > maxi):
maxi = length
maxs = s
S.sort()
i = 0
maxm = 0
mode = 0
while (i < len(S) - 1):
cnt = 1
while True:
if (S[i] == S[i + 1]):
i += 1
cnt += 1
if (i >= len(S) - 1):
break
else:
break
if (cnt > maxm):
maxm = cnt
mode = i
i += 1
print(maxs, S[mode])
|
S = input().split()
maxi = 0
for s in S:
length = len(s)
if (length > maxi):
maxi = length
maxs = s
S.sort()
i = 0
maxm = 0
mode = 0
while (i < len(S) - 1):
cnt = 1
while True:
if (S[i] == S[i + 1]):
i += 1
cnt += 1
if (i >= len(S) - 1):
break
else:
break
if (cnt > maxm):
maxm = cnt
mode = i
i += 1
print(S[mode], maxs)
|
[["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 21], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 21], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22]]
| 5
| 130
| 4
|
targ = input().split(' ')
mostfre = {}
ansfre = ""
longest = [0,""]
for t in targ:
if len(t) > longest[0]:
longest[0],longest[1] = len(t),t
mostfre[t] = mostfre.get(t,0) + 1
temp = 0
print(mostfre)
for k,v in mostfre.items():
if v > temp:
temp = v
ansfre = k
print(ansfre + ' ' + longest[1])
|
targ = input().split(' ')
mostfre = {}
ansfre = ""
longest = [0,""]
for t in targ:
if len(t) > longest[0]:
longest[0],longest[1] = len(t),t
mostfre[t] = mostfre.get(t,0) + 1
temp = 0
for k,v in mostfre.items():
if v > temp:
temp = v
ansfre = k
print(ansfre + ' ' + longest[1])
|
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 117
| 4
|
s = list(input().split())
maxLen = 0
maxNum = 0
dic = {}
for word in s:
if not (word in dic):
dic[word] = 1
else:
dic[word] += 1
if maxNum < dic[word]:
maxNum = dic[word]
ansNum = word
if maxLen < len(word):
maxLen = len(word)
ansLen = word
print(ansNum, ansLen)
print(dic)
|
s = list(input().split())
maxLen = 0
maxNum = 0
dic = {}
for word in s:
if not (word in dic):
dic[word] = 1
else:
dic[word] += 1
if maxNum < dic[word]:
maxNum = dic[word]
ansNum = word
if maxLen < len(word):
maxLen = len(word)
ansLen = word
print(ansNum, ansLen)
|
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 93
| 4
|
dic={}
for word in input().split():
if word not in dic:
dic[word]=0
dic[word]+=1
print(max(iter(dic.keys()),key=lambda k:dic[k]))
print(max(iter(dic.keys()),key= lambda k:len(k)))
|
dic={}
for word in input().split():
if word not in dic:
dic[word]=0
dic[word]+=1
print(max(iter(dic.keys()),key=lambda k:dic[k]), end=' ')
print(max(iter(dic.keys()),key= lambda k:len(k)))
|
[["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 21], ["+", 0, 1, 0, 652, 3, 4, 0, 653, 141, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 653, 0, 32], ["+", 0, 652, 3, 4, 0, 653, 51, 557, 0, 654], ["+", 0, 652, 3, 4, 0, 653, 51, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 653, 51, 557, 0, 655]]
| 5
| 81
| 6
|
word_d={}
for word in input().split():
word_d[word]=word_d.get(word,0)+1
print(max(iter(word_d.keys()), key=lambda i: [i]),max(iter(word_d.keys()),key=lambda i:len(i)))
|
word_d={}
for word in input().split():
word_d[word]=word_d.get(word,0)+1
print(max(iter(word_d.keys()), key=lambda i: word_d[i]),max(iter(word_d.keys()),key=lambda i:len(i)))
|
[["+", 3, 4, 0, 653, 51, 670, 8, 206, 51, 22]]
| 5
| 75
| 1
|
dic={}
s=input().lower().split()
print(s)
for word in s:
try:
dic[word]+=1
except:
dic[word]=1
m=0
l=0
for word, e in list(dic.items()):
if e>m:
m=e
w1=word
if len(word)>l:
l=len(word)
w2=word
print(w1, w2)
|
dic={}
s=input().lower().split()
for word in s:
try:
dic[word]+=1
except:
dic[word]=1
m=0
l=0
for word, e in list(dic.items()):
if e>m:
m=e
w1=word
if len(word)>l:
l=len(word)
w2=word
print(w1, w2)
|
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 96
| 4
|
data = input().strip().split()
stat = {}
for w in data:
if w in stat:
stat[w][0] += 1
else:
stat[w] = [1, len(w)]
count_list = sorted(list(stat.items()), key=lambda x: x[1][0], reverse=True)
length_list = sorted(list(stat.items()), key=lambda x: x[1][1], reverse=True)
print(count_list[0][0])
print(length_list[0][0])
|
data = input().strip().split()
stat = {}
for w in data:
if w in stat:
stat[w][0] += 1
else:
stat[w] = [1, len(w)]
count_list = sorted(list(stat.items()), key=lambda x: x[1][0], reverse=True)
length_list = sorted(list(stat.items()), key=lambda x: x[1][1], reverse=True)
print(count_list[0][0] + " " + length_list[0][0])
|
[["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25], ["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 657, 31, 657, 17, 72], ["+", 3, 4, 0, 657, 31, 657, 12, 557, 0, 654], ["+", 3, 4, 0, 657, 31, 657, 12, 557, 0, 6], ["+", 3, 4, 0, 657, 31, 657, 12, 557, 0, 655], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72]]
| 5
| 131
| 8
|
(function(input) {
var p = input.replace(/\n$/, '').split('\n');
while (true) {
var a = p.shift().split(' ').map(Number);
var n = a.shift();
var s = a.shift();
if (n === 0 && s === 0) {
return;
}
console.log(count(n, s));
}
})(require('fs').readFileSync('/dev/stdin', 'utf8'));
function count(n, s) { return loop(0, n, s); }
function loop(i, n, s) {
var c = 0;
for (var j = i; j < 10; j++) {
s = s - j;
if (n === 1) {
if (s === 0) {
c++;
}
} else {
c += loop(j + 1, n - 1, s);
}
}
return c;
}
|
(function(input) {
var p = input.replace(/\n$/, '').split('\n');
while (true) {
var a = p.shift().split(' ').map(Number);
var n = a.shift();
var s = a.shift();
if (n === 0 && s === 0) {
return;
}
console.log(count(n, s));
}
})(require('fs').readFileSync('/dev/stdin', 'utf8'));
function count(n, s) { return loop(0, n, s); }
function loop(i, n, s) {
// console.log(i, n, s);
var c = 0;
for (var j = i; j < 10; j++) {
var sm = s - j;
if (n === 1) {
if (sm === 0) {
c++;
}
} else {
c += loop(j + 1, n - 1, sm);
}
}
return c;
}
|
[["-", 0, 7, 8, 556, 0, 1, 0, 11, 31, 22], ["+", 8, 556, 0, 7, 8, 556, 0, 198, 0, 217], ["+", 0, 7, 8, 556, 0, 198, 0, 200, 141, 22], ["-", 64, 556, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 64, 556, 0, 57, 15, 23, 0, 16, 31, 22], ["-", 0, 1, 0, 564, 12, 2, 3, 3, 0, 22], ["+", 0, 1, 0, 564, 12, 2, 3, 3, 0, 22]]
| 2
| 218
| 7
|
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) { input += chunk; });
process.stdin.on('end', function() { main(input) });
function main(input) {
var args = input.trim().split('\n');
for (var i = 0; i < args.length; i += 1) {
var set = args[i].split(' ').map(Number);
var n = set[0], s = set[1];
if (!n && !s) {
return;
}
console.log(solve(n, s));
}
}
function solve(n, s) { return countRecursively(s, -1, n - 1); }
function countRecursively(nowS, numPos, step) {
if (step === 0) {
var success = nowS === 0;
return success ? 1 : 0;
}
var total = 0;
for (var i = numPos + 1; i <= 9; i += 1) {
if (nowS >= i) {
total += countRecursively(nowS - i, i, step - 1);
}
}
return total;
}
|
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) { input += chunk; });
process.stdin.on('end', function() { main(input) });
function main(input) {
var args = input.trim().split('\n');
for (var i = 0; i < args.length; i += 1) {
var set = args[i].split(' ').map(Number);
var n = set[0], s = set[1];
if (!n && !s) {
return;
}
console.log(solve(n, s));
}
}
function solve(n, s) { return countRecursively(s, -1, n); }
function countRecursively(nowS, numPos, step) {
if (step === 0) {
var success = nowS === 0;
return success ? 1 : 0;
}
var total = 0;
for (var i = numPos + 1; i <= 9; i += 1) {
if (nowS >= i) {
total += countRecursively(nowS - i, i, step - 1);
}
}
return total;
}
|
[["-", 0, 37, 0, 2, 3, 3, 0, 16, 17, 33], ["-", 0, 37, 0, 2, 3, 3, 0, 16, 12, 555]]
| 2
| 274
| 2
|
<?php
while (TRUE) {
fscanf(STDIN, '%d %d', $n, $s);
if ($n === 0 && $s === 0) {
break;
}
$stack = array(0, 0, -1);
$c = 0;
while (count($stack)) {
$node = array_pop($stack);
if ($node[1] === $n) {
if ($node[0] === $s) {
$c++;
}
continue;
}
for ($i = $node[2] + 1; $i <= 9; $i++) {
$stack[] = array($node[0] + $i, $node[1] + 1, $i);
}
}
echo $c . PHP_EOL;
}
|
<?php
while (TRUE) {
fscanf(STDIN, '%d %d', $n, $s);
if ($n === 0 && $s === 0) {
break;
}
$stack = array(array(0, 0, -1));
$c = 0;
while (count($stack)) {
$node = array_pop($stack);
if ($node[1] === $n) {
if ($node[0] === $s) {
$c++;
}
continue;
}
for ($i = $node[2] + 1; $i <= 9; $i++) {
$stack[] = array($node[0] + $i, $node[1] + 1, $i);
}
}
echo $c . PHP_EOL;
}
|
[["+", 0, 11, 12, 227, 0, 618, 0, 227, 0, 516], ["+", 0, 11, 12, 227, 0, 618, 0, 227, 0, 24], ["+", 0, 11, 12, 227, 0, 618, 0, 227, 0, 25]]
| 6
| 165
| 3
|
import sys
from itertools import combinations as c
for line in sys.stdin:
count = 0
k, v = map(int, line.split())
if k and v:
for i in c(range(10), k):
if sum(i) == v:
count += 1
else:
break
print(count)
|
import sys
from itertools import combinations as c
for line in sys.stdin:
count = 0
k, v = map(int, line.split())
if k or v:
for i in c(range(10), k):
if sum(i) == v:
count += 1
else:
break
print(count)
|
[["-", 0, 7, 8, 196, 0, 57, 15, 679, 17, 355], ["+", 0, 7, 8, 196, 0, 57, 15, 679, 17, 354]]
| 5
| 68
| 2
|
def calc_combination(n, s, max_digit):
if n == 1:
if max_digit > s:
return 0
else:
return 1
if n * (n - 1) / 2 > s:
return 0
total = 0
max_digit = min(s, max_digit)
for i in range(n-1, max_digit):
total += calc_combination(n-1, s-i, max_digit-1)
return total
while True:
n, s = map(int, input().split())
if n == s == 0:
break
print(calc_combination(n, s, 9))
|
def calc_combination(n, s, max_digit):
if n == 1:
if max_digit < s:
return 0
else:
return 1
if n * (n - 1) / 2 > s:
return 0
total = 0
max_digit = min(s, max_digit)
for i in range(n-1, max_digit+1):
total += calc_combination(n-1, s-i, i-1)
return total
while True:
n, s = map(int, input().split())
if n == s == 0:
break
print(calc_combination(n, s, 9))
|
[["-", 0, 57, 64, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 18], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612], ["-", 0, 677, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 677, 12, 652, 3, 4, 0, 657, 31, 22]]
| 5
| 120
| 6
|
from itertools import combinations
while 1:
n,s=map(int,input().split())
if n+x==0:break
print(sum(1 for p in combinations(range(10),n)if sum(p)==s))
|
from itertools import combinations
while 1:
n,s=map(int,input().split())
if n==0:break
print(sum(1 for p in combinations(range(10),n)if sum(p)==s))
|
[["-", 8, 196, 0, 57, 15, 666, 0, 657, 17, 72], ["-", 8, 196, 0, 57, 15, 666, 0, 657, 12, 22]]
| 5
| 57
| 8
|
import sys
import itertools
def solve(x,n,s):
t=[c for c in itertools.combinations(x,n) if sum(c)==s]
return len(t)
x=[i for i in range(10)]
for line in sys.stdin.readlines():
n,s=list(map(int, line.rstrip().split()))
if s==0: break
print(solve(x,n,s))
|
import sys
import itertools
def solve(x,n,s):
t=[c for c in itertools.combinations(x,n) if sum(c)==s]
return len(t)
x=[i for i in range(10)]
for line in sys.stdin.readlines():
n,s=list(map(int, line.rstrip().split()))
if s|n==0: break
print(solve(x,n,s))
|
[["+", 8, 196, 0, 57, 15, 666, 0, 657, 17, 139], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 12, 22]]
| 5
| 103
| 2
|
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from sys import stdin
from itertools import combinations
for line in stdin:
if line.startswith('0 0'):
break
num, ans = (int(s) for s in line.split())
print(sum(sum(t) == ans for t in combinations(range(9), num)))
|
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from sys import stdin
from itertools import combinations
for line in stdin:
if line.startswith('0 0'):
break
num, ans = (int(s) for s in line.split())
print(sum(sum(t) == ans for t in combinations(range(10), num)))
|
[["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 612], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 612]]
| 5
| 78
| 2
|
# -*- coding: utf-8 -*-
import sys
n = 0
s = 0
def combination(n, k):
max = 2 ** n
for i in range(max):
result = [0] * n
for j in range(n):
result[j] = i >> j & 1
cnt = 0
for b in result:
if b == 1:
cnt += 1
if cnt == k:
yield result
for line in sys.stdin:
l = list(map(int, line.strip().split()))
n = l[0]
s = l[1]
if n == 0 and s == 0:
break
ans = 0
for ar in combination(9, n):
sm = 0
for i in range(len(ar)):
if ar[i] == 1:
sm += i
if sm == s:
ans += 1
print(ans)
|
# -*- coding: utf-8 -*-
import sys
n = 0
s = 0
def combination(n, k):
max = 2 ** n
for i in range(max):
result = [0] * n
for j in range(n):
result[j] = i >> j & 1
cnt = 0
for b in result:
if b == 1:
cnt += 1
if cnt == k:
yield result
for line in sys.stdin:
l = list(map(int, line.strip().split()))
n = l[0]
s = l[1]
if n == 0 and s == 0:
break
ans = 0
for ar in combination(10, n):
sm = 0
for i in range(len(ar)):
if ar[i] == 1:
sm += i
if sm == s:
ans += 1
print(ans)
|
[["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612]]
| 5
| 176
| 2
|
def dfs(n, m, s):
if n == N:
return 1 if s == S else 0
ans = 0
for i in range(m, 11 - n):
ans += dfs(n + 1, i + 1, s + i)
return ans;
while True:
N, S = list(map(int, input().split()))
if not N:
break
print(dfs(0, 0, 0))
|
def dfs(n, m, s):
if n == N:
return 1 if s == S else 0
ans = 0
for i in range(m, 10):
ans += dfs(n + 1, i + 1, s + i)
return ans;
while True:
N, S = list(map(int, input().split()))
if not N:
break
print(dfs(0, 0, 0))
|
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 31, 612], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 17, 33], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 12, 22], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612]]
| 5
| 95
| 4
|
def f(mn, n, sm):
if n == 0 and sm == 0:
return 1
if mn == 10 or n == 0 or sm == 0:
return 0
ct = 0
for i in range(mn, min(10, sm + 1)):
ct += f(i + 1, n - 1, sm - i)
return ct
while True:
n, sm = list(map(int, input().split()))
if n == 0 and sm == 0:
break
print(f(0, n, sm))
|
def f(mn, n, sm):
if n == 0 and sm == 0:
return 1
if mn == 10 or n == 0:
return 0
ct = 0
for i in range(mn, min(10, sm + 1)):
ct += f(i + 1, n - 1, sm - i)
return ct
while True:
n, sm = list(map(int, input().split()))
if n == 0 and sm == 0:
break
print(f(0, n, sm))
|
[["-", 0, 14, 8, 196, 0, 57, 15, 679, 17, 354], ["-", 8, 196, 0, 57, 15, 679, 12, 666, 0, 22], ["-", 8, 196, 0, 57, 15, 679, 12, 666, 667, 60], ["-", 8, 196, 0, 57, 15, 679, 12, 666, 0, 612]]
| 5
| 117
| 4
|
def count(target, max_size, c_size, c_num, sum):
if max_size == c_size:
return 1 if sum == target else 0
ans = 0
for i in range(c_num, 10):
ans += count(target, max_size, c_size+1, i+1, sum+i)
return ans
import sys
for s in sys.stdin:
max_size, target = list(map(int, s.split()))
if target == 0 or max_size == 0: break
ans = count(target, max_size, 0, 0, 0)
print(ans)
|
def count(target, max_size, c_size, c_num, sum):
if max_size == c_size:
return 1 if sum == target else 0
ans = 0
for i in range(c_num, 10):
ans += count(target, max_size, c_size+1, i+1, sum+i)
return ans
import sys
for s in sys.stdin:
max_size, target = list(map(int, s.split()))
if target == 0 and max_size == 0: break
ans = count(target, max_size, 0, 0, 0)
print(ans)
|
[["-", 0, 7, 8, 196, 0, 57, 15, 679, 17, 354], ["+", 0, 7, 8, 196, 0, 57, 15, 679, 17, 355]]
| 5
| 116
| 2
|
require("fs").readFileSync("/dev/stdin", "utf8").split('\n').map(function(i) {
for (a = [], j = 0; j < 9; j++)
if ((n = 1 << j) & i)
a.push(n);
if (a[0])
console.log(a.join(' '))
})
|
require("fs").readFileSync("/dev/stdin", "utf8").split('\n').map(function(i) {
for (a = [], j = 0; j <= 9; j++)
if ((n = 1 << j) & i)
a.push(n);
if (a[0])
console.log(a.join(' '))
})
|
[["-", 8, 556, 0, 7, 15, 1, 0, 16, 17, 18], ["+", 8, 556, 0, 7, 15, 1, 0, 16, 17, 19]]
| 2
| 91
| 13
|
var g = [ 1, 2, 4, 8, 16, 32, 64, 128, 512 ];
process.stdin
.on("data",
function(c) {
(c + "").trim().split("\n").some(function(n) {
var a = [], l = 10;
while (l--) {
(n >= g[l]) && (n -= g[l], a.unshift(g[l]));
}
console.log(a.join(" "));
});
})
.resume();
|
var g = [ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 ];
process.stdin
.on("data",
function(c) {
(c + "").trim().split("\n").some(function(n) {
var a = [], l = 10;
while (l--) {
(n >= g[l]) && (n -= g[l], a.unshift(g[l]));
}
console.log(a.join(" "));
});
})
.resume();
|
[["+", 0, 493, 0, 198, 0, 200, 51, 516, 0, 555], ["+", 0, 493, 0, 198, 0, 200, 51, 516, 0, 21]]
| 2
| 132
| 2
|
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
import java.util.stream.IntStream;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] weight =
IntStream.rangeClosed(1, 10).map(e -> (int)Math.pow(2, e)).toArray();
while (sc.hasNext()) {
int n = sc.nextInt();
Deque<Integer> list = new ArrayDeque<>();
for (int i = weight.length - 1; i >= 0; i--) {
if (n >= weight[i]) {
n -= weight[i];
list.push(weight[i]);
}
}
System.out.print(list.pop());
while (!list.isEmpty()) {
System.out.print(" " + list.pop());
}
System.out.println();
}
}
}
|
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
import java.util.stream.IntStream;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] weight =
IntStream.range(0, 10).map(e -> (int)Math.pow(2, e)).toArray();
while (sc.hasNext()) {
int n = sc.nextInt();
Deque<Integer> list = new ArrayDeque<>();
for (int i = weight.length - 1; i >= 0; i--) {
if (n >= weight[i]) {
n -= weight[i];
list.push(weight[i]);
}
}
System.out.print(list.pop());
while (!list.isEmpty()) {
System.out.print(" " + list.pop());
}
System.out.println();
}
}
}
|
[["-", 49, 200, 51, 492, 500, 492, 500, 492, 141, 22], ["+", 49, 200, 51, 492, 500, 492, 500, 492, 141, 22], ["-", 51, 492, 500, 492, 500, 492, 3, 4, 0, 499], ["+", 51, 492, 500, 492, 500, 492, 3, 4, 0, 499]]
| 3
| 221
| 4
|
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String t;
int w, f;
while ((t = bf.readLine()) != null) {
w = Integer.parseInt(t);
f = 0;
for (int i = 0; i < 9; i++)
if ((w >>> i & 1) == 1) {
System.out.print(((f == 0) ? "" : " ") + (int)(1 << i));
f++;
}
System.out.print("\n");
}
}
}
|
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String t;
int w, f;
while ((t = bf.readLine()) != null) {
w = Integer.parseInt(t);
f = 0;
for (int i = 0; i < 10; i++)
if ((w >>> i & 1) == 1) {
System.out.print(((f == 0) ? "" : " ") + (int)(1 << i));
f++;
}
System.out.print("\n");
}
}
}
|
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 12, 499], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 12, 499]]
| 3
| 151
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while (s.hasNext()) {
boolean flag[] = new boolean[10];
int in = s.nextInt();
int a = 1024;
int n = 0;
for (int i = 9; i >= 0; i--) {
a /= 2;
if (in >= a) {
in -= a;
flag[i] = true;
n++;
}
}
int b = 1;
for (int i = 0; i < 10; i++) {
if (flag[i] == true)
n--;
System.out.print(b);
if (n != 0)
System.out.print(" ");
b *= 2;
}
System.out.println();
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while (s.hasNext()) {
boolean flag[] = new boolean[10];
int in = s.nextInt();
int a = 1024;
int n = 0;
for (int i = 9; i >= 0; i--) {
a /= 2;
if (in >= a) {
in -= a;
flag[i] = true;
n++;
}
}
int b = 1;
for (int i = 0; i < 10; i++) {
if (flag[i] == true) {
n--;
System.out.print(b);
if (n != 0)
System.out.print(" ");
}
b *= 2;
}
System.out.println();
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 3
| 188
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
while (stdIn.hasNext()) {
boolean[] answerWeight = {false, false, false, false, false,
false, false, false, false};
int questionWeight = stdIn.nextInt();
if (questionWeight >= 512) {
questionWeight -= 512;
answerWeight[9] = true;
}
if (questionWeight >= 256) {
questionWeight -= 256;
answerWeight[8] = true;
}
if (questionWeight >= 128) {
questionWeight -= 128;
answerWeight[7] = true;
}
if (questionWeight >= 64) {
questionWeight -= 64;
answerWeight[6] = true;
}
if (questionWeight >= 32) {
questionWeight -= 32;
answerWeight[5] = true;
}
if (questionWeight >= 16) {
questionWeight -= 16;
answerWeight[4] = true;
}
if (questionWeight >= 8) {
questionWeight -= 8;
answerWeight[3] = true;
}
if (questionWeight >= 4) {
questionWeight -= 4;
answerWeight[2] = true;
}
if (questionWeight >= 2) {
questionWeight -= 2;
answerWeight[1] = true;
}
if (questionWeight >= 1) {
questionWeight -= 1;
answerWeight[0] = true;
}
for (int i = 0; i < answerWeight.length; i++) {
if (answerWeight[i]) {
System.out.print((int)Math.pow(2, i));
if (!(i == answerWeight.length - 1)) {
for (int j = i + 1; j < answerWeight.length; j++) {
if (answerWeight[j]) {
System.out.print(" ");
break;
}
}
}
}
}
System.out.println();
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
while (stdIn.hasNext()) {
boolean[] answerWeight = {false, false, false, false, false,
false, false, false, false, false};
int questionWeight = stdIn.nextInt();
if (questionWeight >= 512) {
questionWeight -= 512;
answerWeight[9] = true;
}
if (questionWeight >= 256) {
questionWeight -= 256;
answerWeight[8] = true;
}
if (questionWeight >= 128) {
questionWeight -= 128;
answerWeight[7] = true;
}
if (questionWeight >= 64) {
questionWeight -= 64;
answerWeight[6] = true;
}
if (questionWeight >= 32) {
questionWeight -= 32;
answerWeight[5] = true;
}
if (questionWeight >= 16) {
questionWeight -= 16;
answerWeight[4] = true;
}
if (questionWeight >= 8) {
questionWeight -= 8;
answerWeight[3] = true;
}
if (questionWeight >= 4) {
questionWeight -= 4;
answerWeight[2] = true;
}
if (questionWeight >= 2) {
questionWeight -= 2;
answerWeight[1] = true;
}
if (questionWeight >= 1) {
questionWeight -= 1;
answerWeight[0] = true;
}
for (int i = 0; i < answerWeight.length; i++) {
if (answerWeight[i]) {
System.out.print((int)Math.pow(2, i));
if (!(i == answerWeight.length - 1)) {
for (int j = i + 1; j < answerWeight.length; j++) {
if (answerWeight[j]) {
System.out.print(" ");
break;
}
}
}
}
}
System.out.println();
}
}
}
|
[["+", 8, 196, 0, 503, 49, 200, 51, 518, 0, 21], ["+", 8, 196, 0, 503, 49, 200, 51, 518, 0, 147]]
| 3
| 380
| 2
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int n = scan.nextInt();
int count = 0;
int[] w = new int[10];
do {
w[count] = n % 2;
n /= 2;
count++;
} while (n > 0);
for (int i = 0; i < 10; i++) {
if (w[i] == 1) {
if (i == 9) {
System.out.println((int)Math.pow(2, i));
} else {
System.out.print((int)Math.pow(2, i) + " ");
}
}
}
}
}
}
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int n = scan.nextInt();
int count = 0;
int[] w = new int[10];
do {
w[count] = n % 2;
n /= 2;
count++;
} while (n > 0);
for (int i = 0; i < count; i++) {
if (w[i] == 1) {
if (i == count - 1) {
System.out.println((int)Math.pow(2, i));
} else {
System.out.print((int)Math.pow(2, i) + " ");
}
}
}
}
}
}
|
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 12, 499], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 64, 196, 0, 57, 15, 15, 0, 16, 12, 499], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 12, 499]]
| 3
| 175
| 6
|
import java.util.*;
public class Main {
static int Sum(List<Integer> a) {
int result = 0;
for (int i = 0; i < a.size(); i++)
result += a.get(i);
return result;
}
static void print(List<Integer> a) {
Collections.sort(a);
for (int i = 0; i < a.size() - 1; i++) {
System.out.print(a.get(i) + " ");
}
System.out.print(a.get(a.size() - 1));
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int target = in.nextInt();
List<Integer> result = new ArrayList<Integer>();
int n = 0;
int sum = Sum(result);
for (int i = 10; i >= 0; i--) {
if (sum + (1 << i) <= target) {
result.add(1 << i);
sum = Sum(result);
}
}
print(result);
}
}
}
|
import java.util.*;
public class Main {
static int Sum(List<Integer> a) {
int result = 0;
for (int i = 0; i < a.size(); i++)
result += a.get(i);
return result;
}
static void print(List<Integer> a) {
Collections.sort(a);
for (int i = 0; i < a.size() - 1; i++) {
System.out.print(a.get(i) + " ");
}
System.out.println(a.get(a.size() - 1));
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int target = in.nextInt();
List<Integer> result = new ArrayList<Integer>();
int n = 0;
int sum = Sum(result);
for (int i = 10; i >= 0; i--) {
if (sum + (1 << i) <= target) {
result.add(1 << i);
sum = Sum(result);
}
}
print(result);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 492, 141, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 492, 141, 22]]
| 3
| 258
| 2
|
#include <stdio.h>
int main() {
int i, j, n;
while (scanf("%d", &n) != EOF) {
for (j = 0; j < 10; j++) {
if (n & 1 << j) {
printf("%d", 1 << j);
break;
}
}
for (i = j; i < 10; i++) {
if (n & 1 << i)
printf(" %d", 1 << i);
}
printf("\n");
}
return 0;
}
|
#include <stdio.h>
int main() {
int i, j, n;
while (scanf("%d", &n) != EOF) {
for (j = 0; j < 10; j++) {
if (n & 1 << j) {
printf("%d", 1 << j);
break;
}
}
for (i = j + 1; i < 10; i++) {
if (n & 1 << i)
printf(" %d", 1 << i);
}
printf("\n");
}
return 0;
}
|
[["+", 8, 9, 0, 7, 10, 11, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 10, 11, 12, 16, 12, 13]]
| 0
| 113
| 2
|
#include <stdio.h>
int main() {
int w, i;
int m[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}, u[10];
while (scanf("%d", &w) != EOF) {
for (i = 0; i < 9; i++)
u[i] = 0;
for (i = 9; i >= 0; i--)
if (w >= m[i]) {
w -= m[i];
u[i] = 1;
}
for (i = 0, w = 0; i < 9; i++)
if (u[i])
if (!w)
printf("%d", (w++, m[i]));
else
printf(" %d", m[i]);
printf("\n");
}
return 0;
}
|
#include <stdio.h>
int main() {
int w, i;
int m[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}, u[10];
while (scanf("%d", &w) != EOF) {
for (i = 0; i < 9; i++)
u[i] = 0;
for (i = 9; i >= 0; i--)
if (w >= m[i]) {
w -= m[i];
u[i] = 1;
}
for (i = 0, w = 0; i < 10; i++)
if (u[i])
if (!w)
printf("%d", (w++, m[i]));
else
printf(" %d", m[i]);
printf("\n");
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 0
| 189
| 2
|
#include <stdio.h>
int map[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int main(void) {
int num, i, o, line[10];
for (; o = 0, scanf("%d", &num) != EOF;) {
for (i = 9; i >= 0; i--) {
if (num / map[i]) {
line[o++] = map[i];
num -= map[i];
}
}
for (i = o - 1; i >= 0; i--)
printf("%d%s", line[i], i == 0 ? "" : " ");
}
return 0;
}
|
#include <stdio.h>
int map[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int main(void) {
int num, i, o, line[10];
for (; o = 0, scanf("%d", &num) != EOF;) {
for (i = 9; i >= 0; i--) {
if (num / map[i]) {
line[o++] = map[i];
num -= map[i];
}
}
for (i = o - 1; i >= 0; i--)
printf("%d%s", line[i], i == 0 ? "\n" : " ");
}
return 0;
}
|
[["+", 0, 2, 3, 4, 0, 41, 64, 5, 0, 44]]
| 0
| 156
| 1
|
#include <stdio.h>
int main() {
int input;
int weight;
int need[10];
int i, max;
while (scanf("%d", &input) != EOF) {
weight = 512;
max = 0;
for (i = 0; i < 10; i++) {
need[i] = 0;
}
for (i = 9; i >= 0; i--) {
if (weight <= input) {
input -= weight;
need[i] = weight;
if (i > max)
max = i;
}
weight /= 2;
}
i = -1;
for (i = 0; i < max + 1; i++) {
if (need[i]) {
printf("%d", need[i]);
if (i < max)
putchar(' ');
}
}
putchar('a');
}
return 0;
}
|
#include <stdio.h>
int main() {
int input;
int weight;
int need[10];
int i, max;
while (scanf("%d", &input) != EOF) {
weight = 512;
max = 0;
for (i = 0; i < 10; i++) {
need[i] = 0;
}
for (i = 9; i >= 0; i--) {
if (weight <= input) {
input -= weight;
need[i] = weight;
if (i > max)
max = i;
}
weight /= 2;
}
i = -1;
for (i = 0; i < 10; i++) {
if (need[i]) {
printf("%d", need[i]);
if (i < max)
putchar(' ');
}
}
putchar('\n');
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 103, 0, 125], ["+", 0, 1, 0, 2, 3, 4, 0, 103, 0, 44]]
| 0
| 184
| 6
|
#include <stdio.h>
int main() {
int g[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int a, n;
for (;;) {
int low[10] = {0}, f = 0;
if (scanf("%d", &n) == EOF) {
break;
}
for (a = 0; a < 10; a++) {
if (n % 2 == 1) {
low[a] = 1;
}
n = n / 2;
}
for (a = 0; a < 10; a++) {
if (low[a] == 1) {
if (f == 0) {
printf("%d", g[a]);
f = 1;
}
if (f == 1) {
printf(" %d", g[a]);
}
}
}
printf("\n");
}
return 0;
}
|
#include <stdio.h>
int main() {
int g[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int a, n;
for (;;) {
int low[10] = {0}, f = 0;
if (scanf("%d", &n) == EOF) {
break;
}
for (a = 0; a < 10; a++) {
if (n % 2 == 1) {
low[a] = 1;
}
n = n / 2;
}
for (a = 0; a < 10; a++) {
if (low[a] == 1) {
if (f == 0) {
printf("%d", g[a]);
f = 1;
} else if (f == 1) {
printf(" %d", g[a]);
}
}
}
printf("\n");
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 57, 75, 76, 0, 95]]
| 0
| 198
| 1
|
#include <stdio.h>
int main(void) {
int w;
int i;
int f;
while (scanf("%d", &w) != EOF) {
f = 0;
for (i = 0; i < 8; i++) {
if ((w & 1 << i) == 1 << i) {
if (f)
printf(" ");
printf("%d", 1 << i);
f = 1;
}
}
printf("\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int w;
int i;
int f;
while (scanf("%d", &w) != EOF) {
f = 0;
for (i = 0; i < 10; i++) {
if ((w & 1 << i) == 1 << i) {
if (f)
printf(" ");
printf("%d", 1 << i);
f = 1;
}
}
printf("\n");
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 0
| 105
| 2
|
#include <stdio.h>
int main() {
int i, j, x;
int a = 1;
int counter = 0;
int array[9] = {0};
while (scanf("%d", &x) != EOF) {
for (i = 9; i >= 0; i--) {
a = 1;
for (j = 0; j < i; j++) {
a = a * 2;
}
if (x >= a) {
x = x - a;
counter++;
array[counter] = a;
}
}
for (i = counter; i >= 1; i--) {
if (i != 1) {
printf("%d ", array[i]);
} else {
printf("%d\n", array[i]);
}
}
}
return 0;
}
|
#include <stdio.h>
int main() {
int i, j, x;
int a = 1;
int counter = 0;
int array[9] = {0};
while (scanf("%d", &x) != EOF) {
counter = 0;
for (i = 9; i >= 0; i--) {
a = 1;
for (j = 0; j < i; j++) {
a = a * 2;
}
if (x >= a) {
x = x - a;
counter++;
array[counter] = a;
}
}
for (i = counter; i >= 1; i--) {
if (i != 1) {
printf("%d ", array[i]);
} else {
printf("%d\n", array[i]);
}
}
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 0
| 169
| 4
|
#include <iostream>
using namespace std;
int main() {
int w;
while (cin >> w) {
int i = 0;
bool f = 0;
while ((1 << i) < w) {
if ((1 << i) & w) {
if (f)
cout << " ";
else
f = 1;
cout << (1 << i);
}
i++;
}
cout << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int w;
while (cin >> w) {
int i = 0;
bool f = 0;
while ((1 << i) <= w) {
if ((1 << i) & w) {
if (f)
cout << " ";
else
f = 1;
cout << (1 << i);
}
i++;
}
cout << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 19]]
| 1
| 90
| 2
|
#include <iostream>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int w;
while (std::cin >> w) {
for (int i = 0; i < 9; ++i) {
int num = 1 << i;
if (w & num) {
w -= num;
std::cout << num;
if (w) {
std::cout << " ";
}
}
}
std::cout << std::endl;
}
return 0;
}
|
#include <iostream>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int w;
while (std::cin >> w) {
for (int i = 0; i < 10; ++i) {
int num = 1 << i;
if (w & num) {
w -= num;
std::cout << num;
if (w) {
std::cout << " ";
}
}
}
std::cout << std::endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 105
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int w;
while (cin >> w) {
int bit = pow(2, 9);
vector<int> a;
for (int i = 0; i < 10; i++) {
if (w / bit)
a.push_back(bit);
w = w % bit;
bit /= 2;
}
reverse(a.begin(), a.end());
for (int i = 0; i < a.size(); i++) {
cout << a[i];
if (i == a.size() - 1)
cout << endl;
else
cout << ' ';
}
return 0;
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int w;
while (cin >> w) {
int bit = pow(2, 9);
vector<int> a;
for (int i = 0; i < 10; i++) {
if (w / bit)
a.push_back(bit);
w = w % bit;
bit /= 2;
}
reverse(a.begin(), a.end());
for (int i = 0; i < a.size(); i++) {
cout << a[i];
if (i == a.size() - 1)
cout << endl;
else
cout << ' ';
}
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 152
| 2
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int weight[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int gram;
vector<int> ans;
while (cin >> gram) {
for (int i = 9; i >= 0; i--) {
if (gram >= weight[i]) {
ans.push_back(i);
gram -= weight[i];
}
}
for (size_t i = ans.size() - 1; i >= 0; i--) {
cout << weight[ans[i]];
if (i != 0)
cout << ' ';
}
cout << endl;
ans.clear();
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int weight[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int gram;
vector<int> ans;
while (cin >> gram) {
for (int i = 9; i >= 0; i--) {
if (gram >= weight[i]) {
ans.push_back(i);
gram -= weight[i];
}
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << weight[ans[i]];
if (i != 0)
cout << ' ';
}
cout << endl;
ans.clear();
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 10, 43, 39, 40], ["+", 0, 52, 8, 9, 0, 7, 10, 43, 39, 40]]
| 1
| 156
| 2
|
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define PI 3.14159265359
#define INF 1000000;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
typedef long long ll;
using namespace std;
/*
class ElectronicPetEasy
{
public:
string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
{
}
};
*/
int main() {
int weight[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int n;
set<int> weights;
while (cin >> n) {
for (int i = 9; i >= 0; i--) {
if (n >= weight[i]) {
weights.insert(weight[i]);
n -= weight[i];
}
}
bool first_flag = true;
set<int>::iterator it = weights.begin();
while (it != weights.end()) {
if (first_flag) {
cout << *it;
first_flag = false;
} else {
cout << " " << *it;
}
it++;
}
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define PI 3.14159265359
#define INF 1000000;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
typedef long long ll;
using namespace std;
/*
class ElectronicPetEasy
{
public:
string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
{
}
};
*/
int main() {
int weight[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int n;
set<int> weights;
while (cin >> n) {
for (int i = 9; i >= 0; i--) {
if (n >= weight[i]) {
weights.insert(weight[i]);
n -= weight[i];
}
}
bool first_flag = true;
set<int>::iterator it = weights.begin();
while (it != weights.end()) {
if (first_flag) {
cout << *it;
first_flag = false;
} else {
cout << " " << *it;
}
it++;
}
cout << endl;
weights.clear();
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 214
| 6
|
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
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();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (long i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
const long double EPS = 1e-12;
const LL INF = 1e18;
int g[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int main() {
int m;
sort(g, g + 9, greater<int>());
while (cin >> m) {
vector<int> res;
REP(i, 9) {
if (m >= g[i]) {
m %= g[i];
res.PB(g[i]);
}
}
SORT(res);
REP(i, SZ(res)) {
cout << res[i];
if (i != SZ(res) - 1)
cout << " ";
}
cout << endl;
}
return 0;
}
/*
*/
|
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
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();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (long i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
const long double EPS = 1e-12;
const LL INF = 1e18;
int g[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int main() {
int m;
sort(g, g + 10, greater<int>());
while (cin >> m) {
vector<int> res;
REP(i, 10) {
if (m >= g[i]) {
m %= g[i];
res.PB(g[i]);
}
}
SORT(res);
REP(i, SZ(res)) {
cout << res[i];
if (i != SZ(res) - 1)
cout << " ";
}
cout << endl;
}
return 0;
}
/*
*/
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
| 1
| 418
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define PI 3.141592653
bool cross(double x1, double y1, double x2, double y2, double x3, double y3,
double x4, double y4) {
double a, b, c, d;
a = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1);
b = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2);
c = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3);
d = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4);
if ((c < 0) ^ (d < 0))
return true;
else
return false;
}
int main() {
int w;
while (EOF != scanf("%d", &w)) {
bool f = true;
for (int i = 0; i < 9; i++) {
if (w & (1 << i)) {
printf(f ? "%d" : " %d", (int)pow(2, i));
f = false;
}
}
printf("\n");
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define PI 3.141592653
bool cross(double x1, double y1, double x2, double y2, double x3, double y3,
double x4, double y4) {
double a, b, c, d;
a = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1);
b = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2);
c = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3);
d = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4);
if ((c < 0) ^ (d < 0))
return true;
else
return false;
}
int main() {
int w;
while (EOF != scanf("%d", &w)) {
bool f = true;
for (int i = 0; i <= 9; i++) {
if (w & (1 << i)) {
printf(f ? "%d" : " %d", (int)pow(2, i));
f = false;
}
}
printf("\n");
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 288
| 2
|
#include <stdio.h>
#include <string.h>
int main(void) {
char line[80];
int w;
int f[10];
int u[10];
int k = 512;
for (int &d : f) {
d = k;
k >>= 1;
}
while (true) {
if (fgets(line, sizeof line, stdin) == NULL) {
break;
}
if (sscanf(line, "%d", &w) != 1) {
break;
}
int p;
for (p = 0; p < 10; p++) {
if (w > f[p]) {
break;
}
}
memset(u, 0, sizeof u);
int t = f[p];
u[p] = 1;
p++;
while (true) {
if (t == w) {
break;
} else if (t > w) {
t -= f[p - 1];
u[p - 1] = 0;
}
t += f[p];
u[p] = 1;
p++;
}
const char *sp = "";
for (int i = 9; i >= 0; i--) {
if (u[i]) {
printf("%s%d", sp, f[i]);
if (*sp == 0) {
sp = " ";
}
}
}
printf("\n");
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
char line[80];
int w;
int f[10];
int u[10];
int k = 512;
for (int &d : f) {
d = k;
k >>= 1;
}
while (true) {
if (fgets(line, sizeof line, stdin) == NULL) {
break;
}
if (sscanf(line, "%d", &w) != 1) {
break;
}
int p;
for (p = 0; p < 10; p++) {
if (w >= f[p]) {
break;
}
}
memset(u, 0, sizeof u);
int t = f[p];
u[p] = 1;
p++;
while (true) {
if (t == w) {
break;
} else if (t > w) {
t -= f[p - 1];
u[p - 1] = 0;
}
t += f[p];
u[p] = 1;
p++;
}
const char *sp = "";
for (int i = 9; i >= 0; i--) {
if (u[i]) {
printf("%s%d", sp, f[i]);
if (*sp == 0) {
sp = " ";
}
}
}
printf("\n");
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 290
| 2
|
#include <bits/stdc++.h>
using namespace std;
int N, S;
int dfs(int n, int t, int sum) {
if (n == 10)
return 0;
if (t == N) {
if (sum == S)
return 1;
else
return 0;
}
return dfs(n + 1, t, sum) + dfs(n + 1, t + 1, sum + n);
}
int main() {
while (cin >> N >> S, N || S)
cout << dfs(0, 0, 0) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, S;
int dfs(int n, int t, int sum) {
if (n > 10)
return 0;
if (t == N) {
if (sum == S)
return 1;
else
return 0;
}
return dfs(n + 1, t, sum) + dfs(n + 1, t + 1, sum + n);
}
int main() {
while (cin >> N >> S, N || S)
cout << dfs(0, 0, 0) << endl;
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 116
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(false);
for (int n, s; cin >> n >> s;)
if (n && s) {
int p[10];
iota(p, p + 10, 0);
int ans = 0;
do {
if (accumulate(p, p + n, 0) == s)
ans++;
} while (next_permutation(p, p + 10));
for (int i = 1; i <= 10 - n; i++)
ans /= i;
for (int i = 1; i <= n; i++)
ans /= i;
cout << ans << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(false);
for (int n, s; cin >> n >> s;)
if (n || s) {
int p[10];
iota(p, p + 10, 0);
int ans = 0;
do {
if (accumulate(p, p + n, 0) == s)
ans++;
} while (next_permutation(p, p + 10));
for (int i = 1; i <= 10 - n; i++)
ans /= i;
for (int i = 1; i <= n; i++)
ans /= i;
cout << ans << '\n';
}
return 0;
}
|
[["-", 0, 7, 8, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 7, 8, 57, 15, 339, 51, 16, 17, 106]]
| 1
| 145
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.