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
|
|---|---|---|---|---|---|
from sys import stdin
if __name__ == '__main__':
for n in stdin:
if int(n) == 0:
break
bottom_total = []
right_total = []
for _ in range(int(n)):
line = input().split(' ')
total = 0
for i, v in enumerate(line):
print(repr(int(v)).rjust(5), end='')
total += int(v)
if len(bottom_total) < _ + 1:
bottom_total.append(int(v))
else:
bottom_total[_] += int(v)
right_total.append(total)
print(repr(right_total[_]).rjust(5))
for num in bottom_total:
print(repr(num).rjust(5), end='')
print(repr(sum(right_total)).rjust(5))
|
from sys import stdin
if __name__ == '__main__':
# is_begin = False
for n in stdin:
if int(n) == 0:
break
# else:
# if is_begin:
# print()
# is_begin = True
bottom_total = []
right_total = []
for _ in range(int(n)):
line = input().split(' ')
total = 0
for i, v in enumerate(line):
print(repr(int(v)).rjust(5), end='')
total += int(v)
if len(bottom_total) < i + 1:
bottom_total.append(int(v))
else:
bottom_total[i] += int(v)
right_total.append(total)
print(repr(right_total[_]).rjust(5))
for num in bottom_total:
print(repr(num).rjust(5), end='')
print(repr(sum(bottom_total)).rjust(5))
|
[["-", 8, 196, 0, 57, 15, 666, 0, 657, 31, 22], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 31, 22], ["-", 8, 196, 0, 1, 0, 677, 31, 206, 206, 22], ["+", 8, 196, 0, 1, 0, 677, 31, 206, 206, 22], ["-", 500, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 500, 652, 3, 4, 0, 652, 3, 4, 0, 22]]
| 5
| 183
| 6
|
while 1:
n=int(input())
if n==0:break;
a=[]
for i in range(n):
a[i]=[list(map(int,input().split()))]
a[i]+=[sum(a[i])]
for s in a[i]:print("%5d"%s,end='')
print()
for c in zip(*a):print("%5d"%sum(c),end='')
print()
|
while 1:
n=int(input())
if n==0:break;
a=[]
for i in range(n):
a+=[list(map(int,input().split()))]
a[i]+=[sum(a[i])]
for s in a[i]:print("%5d"%s,end='')
print()
for c in zip(*a):print("%5d"%sum(c),end='')
print()
|
[["-", 8, 196, 0, 1, 0, 662, 31, 206, 0, 70], ["-", 8, 196, 0, 1, 0, 662, 31, 206, 206, 22], ["-", 8, 196, 0, 1, 0, 662, 31, 206, 0, 73], ["-", 0, 7, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 677, 17, 107]]
| 5
| 118
| 19
|
<?php
$inning = trim(fgets(STDIN));
$scores = array();
for($i = 0; $i < $inning; ++$i) {
$scores[$i] = 0;
}
$outcount = 0;
$base = 0;
while(true) {
$turn = floor($outcount / 3);
$key = trim(fgets(STDIN));
switch($key) {
case 'HIT':
$scores[$turn] += $base & 1;
$base = ($base >> 1) | 4;
break;
case 'OUT':
if (++$outcount == 3) {
$base = 0;
}
break;
case 'HOMERUN':
$base |= 8;
while ($base) {
$scores[$turn] += $base & 1;
$base = $base >> 1;
}
break;
}
if ($outcount == 3 * $inning) {
break;
}
}
foreach ($scores as $score) {
echo $score . PHP_EOL;
}
|
<?php
$inning = trim(fgets(STDIN));
$scores = array();
for($i = 0; $i < $inning; ++$i) {
$scores[$i] = 0;
}
$outcount = 0;
$base = 0;
while(true) {
$turn = floor($outcount / 3);
$key = trim(fgets(STDIN));
switch($key) {
case 'HIT':
$scores[$turn] += $base & 1;
$base = ($base >> 1) | 4;
break;
case 'OUT':
if (++$outcount%3 == 0) {
$base = 0;
}
break;
case 'HOMERUN':
$base |= 8;
while ($base) {
$scores[$turn] += $base & 1;
$base = $base >> 1;
}
break;
}
if ($outcount == 3 * $inning) {
break;
}
}
foreach ($scores as $score) {
echo $score . PHP_EOL;
}
|
[["-", 0, 100, 0, 57, 15, 23, 0, 16, 17, 60], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 109], ["+", 0, 100, 0, 57, 15, 23, 0, 16, 17, 60], ["+", 0, 100, 0, 57, 15, 23, 0, 16, 12, 612]]
| 6
| 214
| 4
|
import java.util.Scanner;
// import java.io.*;
// import java.util.Arrays;
public class Main {
public static void main(String[] args) throws java.io.IOException {
Scanner scan = new Scanner(System.in);
// InputStreamReader is = new InputStreamReader(System.in);
// BufferedReader br = new BufferedReader(is);
int n = scan.nextInt();
int tensuu[] = new int[n];
String action;
for (int i = 0; i < n; i++) {
int out = 0;
int rui = 0;
while (out < 3) {
action = scan.next();
if (action.equals("OUT")) {
++out;
} else if (action.equals("HIT")) {
++rui;
if (rui == 4) {
++tensuu[i];
rui = 3;
}
} else {
tensuu[0] += rui + 1;
rui = 0;
}
}
}
for (int i = 0; i < n; i++) {
System.out.println(tensuu[i]);
}
}
}
|
import java.util.Scanner;
// import java.io.*;
// import java.util.Arrays;
public class Main {
public static void main(String[] args) throws java.io.IOException {
Scanner scan = new Scanner(System.in);
// InputStreamReader is = new InputStreamReader(System.in);
// BufferedReader br = new BufferedReader(is);
int n = scan.nextInt();
int tensuu[] = new int[n];
String action;
for (int i = 0; i < n; i++) {
int out = 0;
int rui = 0;
while (out < 3) {
action = scan.next();
if (action.equals("OUT")) {
++out;
} else if (action.equals("HIT")) {
++rui;
if (rui == 4) {
++tensuu[i];
rui = 3;
}
} else {
tensuu[i] += rui + 1;
rui = 0;
}
}
}
for (int i = 0; i < n; i++) {
System.out.println(tensuu[i]);
}
}
}
|
[["-", 75, 196, 0, 1, 0, 11, 31, 504, 71, 499], ["+", 75, 196, 0, 1, 0, 11, 31, 504, 71, 22]]
| 3
| 205
| 2
|
import java.util.*;
class Main {
public static void main(String[] z) {
Scanner s = new Scanner(System.in);
String x;
for (int t = s.nextInt(), r, p, o, b; t-- > 0; System.out.println(p))
for (r = p = o = 0; !(x = s.next()).equals("OUT") || ++o < 3;) {
if (x.equals("HIT")) {
b = r > 2 ? 1 : 0;
p += b;
r += 1 - b;
}
if (x.matches("H.+N")) {
p += r > 2 ? 3 : r + 1;
r = 0;
}
}
}
}
|
import java.util.*;
class Main {
public static void main(String[] z) {
Scanner s = new Scanner(System.in);
String x;
for (int t = s.nextInt(), r, p, o, b; t-- > 0; System.out.println(p))
for (r = p = o = 0; !(x = s.next()).equals("OUT") || ++o < 3;) {
if (x.equals("HIT")) {
b = r > 2 ? 1 : 0;
p += b;
r += 1 - b;
}
if (x.matches("H.+N")) {
p += r > 2 ? 4 : r + 1;
r = 0;
}
}
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 12, 510, 64, 499], ["+", 64, 196, 0, 1, 0, 11, 12, 510, 64, 499]]
| 3
| 168
| 2
|
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
public class Main {
Scanner sc;
static final int INF = 1 << 28;
static final double EPS = 1e-9;
void run() {
sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int out = 0;
int score = 0;
boolean[] runner = new boolean[3];
for (; out < 3;) {
String s = sc.next();
if (s.equals("HIT")) {
if (runner[2])
score++;
runner[2] = runner[1];
runner[1] = runner[0];
runner[0] = true;
} else if (s.equals("HOMERUN")) {
for (int j = 0; j < 3; j++) {
if (runner[i])
score++;
runner[i] = false;
}
score++;
} else {
out++;
}
}
println(score + "");
}
sc.close();
}
void print(String s) { System.out.print(s); }
void println(String s) { System.out.println(s); }
public static void main(String[] args) { new Main().run(); }
}
|
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
public class Main {
Scanner sc;
static final int INF = 1 << 28;
static final double EPS = 1e-9;
void run() {
sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int out = 0;
int score = 0;
boolean[] runner = new boolean[3];
for (; out < 3;) {
String s = sc.next();
if (s.equals("HIT")) {
if (runner[2])
score++;
runner[2] = runner[1];
runner[1] = runner[0];
runner[0] = true;
} else if (s.equals("HOMERUN")) {
for (int j = 0; j < 3; j++) {
if (runner[j])
score++;
runner[j] = false;
}
score++;
} else {
out++;
}
}
println(score + "");
}
sc.close();
}
void print(String s) { System.out.print(s); }
void println(String s) { System.out.println(s); }
public static void main(String[] args) { new Main().run(); }
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 504, 71, 22], ["+", 8, 196, 0, 57, 15, 15, 0, 504, 71, 22], ["-", 8, 196, 0, 1, 0, 11, 31, 504, 71, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 504, 71, 22]]
| 3
| 328
| 4
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
List<Integer> result = new ArrayList<Integer>();
int n = stdIn.nextInt();
int count = 0;
int[] base = new int[4];
while (n != 0) {
String str = stdIn.next();
if (str.equals("HIT")) {
base[3] += base[2];
base[2] = base[1];
base[1] = base[0];
base[0] = 1;
} else if (str.equals("HOMERUN")) {
base[3] += (base[2] + base[1] + base[0] + 1);
base[2] = 0;
base[1] = 0;
base[0] = 0;
} else {
count++;
}
if (count == 3) {
n--;
result.add(base[3]);
base = new int[4];
}
}
for (Integer score : result) {
System.out.println(score);
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
List<Integer> result = new ArrayList<Integer>();
int n = stdIn.nextInt();
int count = 0;
int[] base = new int[4];
while (n != 0) {
String str = stdIn.next();
if (str.equals("HIT")) {
base[3] += base[2];
base[2] = base[1];
base[1] = base[0];
base[0] = 1;
} else if (str.equals("HOMERUN")) {
base[3] += (base[2] + base[1] + base[0] + 1);
base[2] = 0;
base[1] = 0;
base[0] = 0;
} else {
count++;
}
if (count == 3) {
n--;
result.add(base[3]);
base = new int[4];
count = 0;
}
}
for (Integer score : result) {
System.out.println(score);
}
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 499], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 3
| 253
| 4
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
final String HIT = "HIT", HOMERUN = "HOMERUN", OUT = "OUT";
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int out, point, rui;
String j;
for (int i = 0; i < n; i++) {
out = 0;
point = 0;
rui = 0;
while (out < 3) {
j = in.next();
if (OUT.equals(j)) {
out++;
} else if (HIT.equals(j)) {
rui++;
if (rui > 3) {
rui = 3;
point++;
}
} else if (HOMERUN.equals(j)) {
point += rui + 1;
rui = 0;
}
}
System.out.print(point);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
final String HIT = "HIT", HOMERUN = "HOMERUN", OUT = "OUT";
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int out, point, rui;
String j;
for (int i = 0; i < n; i++) {
out = 0;
point = 0;
rui = 0;
while (out < 3) {
j = in.next();
if (OUT.equals(j)) {
out++;
} else if (HIT.equals(j)) {
rui++;
if (rui > 3) {
rui = 3;
point++;
}
} else if (HOMERUN.equals(j)) {
point += rui + 1;
rui = 0;
}
}
System.out.println(point);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 492, 141, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 492, 141, 22]]
| 3
| 193
| 2
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n, rui, out, score;
char ive[30];
scanf("%d", &n);
if (n == 0)
return (0);
while (n != 0) {
n--;
rui = 0;
out = 0;
score = 0;
while (out < 3) {
scanf("%s", ive);
if (strcmp(ive, "HIT") == 0) {
rui++;
if (rui > 4) {
score += rui - 3;
rui--;
}
} else if (strcmp(ive, "HOMERUN") == 0) {
score += rui + 1;
rui = 0;
} else if (strcmp(ive, "OUT") == 0) {
out++;
}
}
printf("%d\n", score);
}
return (0);
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n, rui, out, score;
char ive[30];
scanf("%d", &n);
if (n == 0)
return (0);
while (n != 0) {
n--;
rui = 0;
out = 0;
score = 0;
while (out < 3) {
scanf("%s", ive);
if (strcmp(ive, "HIT") == 0) {
rui++;
if (rui > 3) {
score += rui - 3;
rui--;
// printf("%d\n", score);
}
} else if (strcmp(ive, "HOMERUN") == 0) {
score += rui + 1;
rui = 0;
// printf("%d\n", score);
} else if (strcmp(ive, "OUT") == 0) {
out++;
// printf("%d\n", score);
}
}
printf("%d\n", score);
}
return (0);
}
|
[["-", 64, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 64, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 182
| 2
|
#include <stdio.h>
int main() {
int n, hitcount = 0, outcount = 0, point = 0;
char s[8];
scanf("%d", &n);
while (1) {
scanf("%s", &s);
if (s[1] == 'U')
outcount++;
if (outcount == 3) {
printf("%d\n", point);
point = 0;
n--;
outcount = 0;
}
if (!n)
break;
if (s[1] == 'I')
hitcount++;
if (hitcount == 4) {
point++;
hitcount = 3;
}
if (s[1] == 'O') {
point += hitcount;
hitcount = 0;
point++;
}
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, hitcount = 0, outcount = 0, point = 0;
char s[8];
scanf("%d", &n);
while (1) {
scanf("%s", &s);
if (s[1] == 'U')
outcount++;
if (outcount == 3) {
printf("%d\n", point);
point = 0;
n--;
outcount = 0;
hitcount = 0;
}
if (!n)
break;
if (s[1] == 'I')
hitcount++;
if (hitcount == 4) {
point++;
hitcount = 3;
}
if (s[1] == 'O') {
point += hitcount;
hitcount = 0;
point++;
}
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 0
| 161
| 4
|
#include <stdio.h>
#include <string.h>
int main() {
int n;
scanf("%d", &n);
int coutOUT = 0, coutHIT = 0, point = 0;
;
char event[10];
while (n) {
while (coutOUT < 3) {
scanf("%s", event);
if (strcmp(event, "HIT") == 0) {
coutHIT += 1;
if (coutHIT == 4) {
point += 1;
coutHIT = 4;
}
}
if (strcmp(event, "OUT") == 0) {
coutOUT += 1;
}
if (strcmp(event, "HOMERUN") == 0) {
point += coutHIT + 1;
coutHIT = 0;
}
}
printf("%d\n", point);
coutHIT = 0;
coutOUT = 0;
point = 0;
n -= 1;
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main() {
int n;
scanf("%d", &n);
int coutOUT = 0, coutHIT = 0, point = 0;
;
char event[10];
while (n) {
while (coutOUT < 3) {
scanf("%s", event);
if (strcmp(event, "HIT") == 0) {
coutHIT += 1;
if (coutHIT == 4) {
point += 1;
coutHIT = 3;
}
}
if (strcmp(event, "OUT") == 0) {
coutOUT += 1;
}
if (strcmp(event, "HOMERUN") == 0) {
point += coutHIT + 1;
coutHIT = 0;
}
}
printf("%d\n", point);
coutHIT = 0;
coutOUT = 0;
point = 0;
n -= 1;
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13]]
| 0
| 174
| 2
|
o, x, b;
main(a) {
for (scanf("%d"); ~scanf("%s", &a);
o == 3 ? o = b = x = !printf("%d\n", x) : 0)
for (a %= 8, a - 7 ? b = b * 2 + 1, x += b / 8, b &= 7 : o++; !a & b;
b /= 2)
x++;
}
|
o, x, b;
main(a) {
for (scanf("%d"); ~scanf("%s", &a);
o == 3 ? o = b = x = !printf("%d\n", x) : 0)
for (a %= 6, a - 5 ? b = b * 2 + 1, x += b / 8, b &= 7 : o++; !a & b;
b /= 2)
x++;
}
|
[["-", 0, 7, 8, 7, 10, 34, 31, 11, 12, 13], ["+", 0, 7, 8, 7, 10, 34, 31, 11, 12, 13], ["-", 8, 7, 10, 34, 12, 34, 31, 16, 12, 13], ["+", 8, 7, 10, 34, 12, 34, 31, 16, 12, 13]]
| 0
| 98
| 4
|
o, x, b;
main(a) {
for (scanf("%d"); ~scanf("%s", &a); !a ? x += b + 1,
b = 0 : a - 5 ? x += ++b > 3 ? x = 3,
1
: 0
: ++o == 3 ? o = b = x = !printf("%d\n", x)
: 0)
a %= 6;
}
|
o, x, b;
main(a) {
for (scanf("%d"); ~scanf("%s", &a); !a ? x += b + 1,
b = 0 : a - 5 ? x += ++b > 3 ? b = 3,
1
: 0
: ++o == 3 ? o = b = x = !printf("%d\n", x)
: 0)
a %= 6;
}
|
[["-", 64, 11, 12, 41, 0, 42, 0, 11, 31, 22], ["+", 64, 11, 12, 41, 0, 42, 0, 11, 31, 22]]
| 0
| 92
| 2
|
// AOJ Volume 1 Problem 0103
#include <stdio.h>
#include <string.h>
int main(void) {
int n;
char event[8];
int base1, base2, base3;
int out;
int score;
int i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
base1 = base2 = base3 = out = score = 0;
while (1) {
scanf("%s", event);
if (strcmp(event, "HIT") == 0) {
score += base3;
base3 = base2;
base2 = base1;
base1 = 1;
} else if (strcmp(event, "HOMERUN") == 0) {
score += (base1 + base2 + base3 + 1);
base1 = base2 = base2 = 0;
} else {
out++;
if (out == 3) {
break;
}
}
}
printf("%d\n", score);
}
return (0);
}
|
// AOJ Volume 1 Problem 0103
#include <stdio.h>
#include <string.h>
int main(void) {
int n;
char event[8];
int base1, base2, base3;
int out;
int score;
int i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
base1 = base2 = base3 = out = score = 0;
while (1) {
scanf("%s", event);
if (strcmp(event, "HIT") == 0) {
score += base3;
base3 = base2;
base2 = base1;
base1 = 1;
} else if (strcmp(event, "HOMERUN") == 0) {
score += (base1 + base2 + base3 + 1);
base1 = base2 = base3 = 0;
} else {
out++;
if (out == 3) {
break;
}
}
}
printf("%d\n", score);
}
return (0);
}
|
[["-", 0, 1, 0, 11, 12, 11, 12, 11, 31, 22], ["+", 0, 1, 0, 11, 12, 11, 12, 11, 31, 22]]
| 0
| 187
| 2
|
#include <stdio.h>
int main(void) {
int game_no;
int base;
int out;
int point;
char event[3];
scanf("%d", &game_no);
while (game_no--) {
point = base = out = 0;
while (out - 3) {
scanf("%2s", event);
if (event[0] == 'H') {
if (++base > 3) {
point++;
base = 3;
}
if (event[1] == 'O') {
point += base;
base = 0;
}
} else
out++;
}
printf("%d\n", point);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int game_no;
int base;
int out;
int point;
char event[9];
scanf("%d", &game_no);
while (game_no--) {
point = base = out = 0;
while (out - 3) {
scanf("%7s", event);
if (event[0] == 'H') {
if (++base > 3) {
point++;
base = 3;
}
if (event[1] == 'O') {
point += base;
base = 0;
}
} else
out++;
}
printf("%d\n", point);
}
return (0);
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 138
| 4
|
b, o, s;
main(a) {
for (scanf("%d"); ~scanf("%s", &a);)
b = a % 3 ? a & 1
? ++o % 3 ? b : (s = !printf("%d\n", b > 3 ? s + b - 3 : s))
: b + 1
: (s += b + 1);
}
|
b, o, s;
main(a) {
for (scanf("%d"); ~scanf("%s", &a);)
b = a % 3 ? a & 1
? ++o % 3 ? b : (s = !printf("%d\n", b > 3 ? s + b - 3 : s))
: b + 1
: !(s += b + 1);
}
|
[["+", 8, 1, 0, 11, 12, 41, 75, 91, 17, 111]]
| 0
| 87
| 14
|
b, o, s;
main(a) {
for (; ~scanf("%s", &a);)
a - 249 &&
(b = a % 3 ? a & 1 ? ++o % 3
? b
: (s = !printf("%d\n", b > 3 ? s + b - 3 : s))
: b + 1
: !(s -= ~b));
}
|
b, o, s;
main(a) {
for (; ~scanf("%s", &a);)
a < 1e5
?: (b = a % 3 ? a & 1
? ++o % 3
? b
: (s = !printf("%d\n", b > 3 ? s + b - 3 : s))
: b + 1
: !(s -= ~b));
}
|
[["-", 0, 7, 8, 1, 0, 16, 31, 16, 17, 33], ["-", 0, 7, 8, 1, 0, 16, 31, 16, 12, 13], ["-", 8, 9, 0, 7, 8, 1, 0, 16, 17, 98], ["+", 0, 7, 8, 1, 0, 41, 15, 16, 17, 18], ["+", 0, 7, 8, 1, 0, 41, 15, 16, 12, 13], ["+", 8, 9, 0, 7, 8, 1, 0, 41, 0, 101], ["+", 8, 9, 0, 7, 8, 1, 0, 41, 0, 102]]
| 0
| 87
| 7
|
#include <stdio.h>
#include <string.h>
int main() {
int a, n, run = 0, point = 0, out = 0;
char eve[10];
scanf("%d", &n);
for (a = 0; a < n;) {
scanf("%s", eve);
if (strcmp(eve, "HIT") == 0) {
if (run != 3)
run++;
else {
point++;
run = 0;
}
} else if (strcmp(eve, "HOMERUN") == 0) {
point += run + 1;
run = 0;
} else if (strcmp(eve, "OUT") == 0) {
if (out != 2)
out++;
else {
a++;
printf("%d\n", point);
run = 0, point = 0, out = 0;
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main() {
int a, n, run = 0, point = 0, out = 0;
char eve[10];
scanf("%d", &n);
for (a = 0; a < n;) {
scanf("%s", eve);
if (strcmp(eve, "HIT") == 0) {
if (run != 3)
run++;
else {
point++;
}
} else if (strcmp(eve, "HOMERUN") == 0) {
point += run + 1;
run = 0;
} else if (strcmp(eve, "OUT") == 0) {
if (out != 2)
out++;
else {
a++;
printf("%d\n", point);
run = 0, point = 0, out = 0;
}
}
}
return 0;
}
|
[["-", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["-", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["-", 75, 76, 0, 9, 0, 1, 0, 11, 12, 13], ["-", 0, 57, 75, 76, 0, 9, 0, 1, 0, 35]]
| 0
| 181
| 4
|
#include <stdio.h>
#include <string.h>
int main(void) {
int HIT = 0, OUT = 0, POINT = 0, a, b, c = 0;
char EVENT[8];
for (;;) {
scanf("%d", &a);
for (b = 0;; b++) {
scanf("%s", &EVENT);
if (strcmp(EVENT, "OUT") == 0)
OUT++;
if (strcmp(EVENT, "HIT") == 0)
if (HIT == 4)
POINT++;
else
HIT++;
if (strcmp(EVENT, "HOMERUN") == 0) {
POINT += HIT + 1;
HIT = 0;
}
if (OUT == 3) {
printf("%d\n", POINT);
POINT = OUT = HIT = 0;
c++;
if (c == a)
return 0;
}
}
}
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int HIT = 0, OUT = 0, POINT = 0, a, b, c = 0;
char EVENT[8];
for (;;) {
scanf("%d", &a);
for (b = 0;; b++) {
scanf("%s", &EVENT);
if (strcmp(EVENT, "OUT") == 0)
OUT++;
if (strcmp(EVENT, "HIT") == 0)
if (HIT == 3)
POINT++;
else
HIT++;
if (strcmp(EVENT, "HOMERUN") == 0) {
POINT += HIT + 1;
HIT = 0;
}
if (OUT == 3) {
printf("%d\n", POINT);
POINT = OUT = HIT = 0;
c++;
if (c == a)
return 0;
}
}
}
}
|
[["-", 0, 57, 64, 57, 15, 23, 0, 16, 12, 13], ["+", 0, 57, 64, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 182
| 2
|
#include <stdio.h>
#include <string.h>
#define OUT_COUNT 0
#define POINT_COUNT 1
void initilaize(char array[]);
void process(int count[]); //処理関数
main() {
int i = 0, n = 0;
int count[2];
scanf("%d\n", &n);
while (i < n) {
count[0] = 0, count[1] = 0; //初期化
process(count); //処理関数呼び出し
printf("%d\n", count[POINT_COUNT]);
i++;
}
return 0;
}
void initialize(char array[]) {
short i = 0;
for (i = 0; i < 8; i++) {
array[i] = 0x00;
}
}
void process(int count[]) //処理関数
{
char event[8];
short base = 0;
int i = 0;
int runner = 0;
while (count[OUT_COUNT] < 3) //アウトカウントが3になるまで
{
initialize(event); //イベント代入配列の初期化
gets(event); //イベントの取得
if (strcmp(event, "OUT") == 0) {
count[OUT_COUNT]++;
} else if (strcmp(event, "HIT") == 0) {
base++;
if (base > 4) {
count[POINT_COUNT]++;
base--;
}
} else if (strcmp(event, "HOMERUN") == 0) {
count[POINT_COUNT] += base + 1;
base = 0;
}
// printf("count[POINT_COUNT] = %d\n", count[POINT_COUNT]);
}
return;
}
|
#include <stdio.h>
#include <string.h>
#define OUT_COUNT 0
#define POINT_COUNT 1
void initilaize(char array[]);
void process(int count[]); //処理関数
main() {
int i = 0, n = 0;
int count[2];
scanf("%d\n", &n);
while (i < n) {
count[0] = 0, count[1] = 0; //初期化
process(count); //処理関数呼び出し
printf("%d\n", count[POINT_COUNT]);
i++;
}
return 0;
}
void initialize(char array[]) {
short i = 0;
for (i = 0; i < 8; i++) {
array[i] = 0x00;
}
}
void process(int count[]) //処理関数
{
char event[8];
short base = 0;
int i = 0;
int runner = 0;
while (count[OUT_COUNT] < 3) //アウトカウントが3になるまで
{
initialize(event); //イベント代入配列の初期化
gets(event); //イベントの取得
if (strcmp(event, "OUT") == 0) {
count[OUT_COUNT]++;
} else if (strcmp(event, "HIT") == 0) {
base++;
if (base > 3) {
count[POINT_COUNT]++;
base--;
}
} else if (strcmp(event, "HOMERUN") == 0) {
count[POINT_COUNT] += base + 1;
base = 0;
}
// printf("count[OUT_COUNT] = %d base = %d\n", count[OUT_COUNT], base);
// printf("count[POINT_COUNT] = %d\n", count[POINT_COUNT]);
}
return;
}
|
[["-", 64, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 64, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 291
| 2
|
// Name: Baseball Simulation
// Level: 1
// Category: やるだけ
// Note:
/**
* 仕様のとおりに実装する。
*
* オーダーは O(E)。
* ただし、Eはイベントの個数。
*/
#include <iostream>
#include <string>
using namespace std;
bool solve() {
int out = 0;
int b1 = 0, b2 = 0, b3 = 0;
int score = 0;
while (out < 3) {
string event;
cin >> event;
if (event == "HIT") {
if (b3)
++score;
b3 = b2;
b2 = b1;
b1 = 1;
} else if (event == "HOMERUN") {
score = b1 + b2 + b3 + 1;
b1 = b2 = b3 = 0;
} else if (event == "OUT") {
++out;
}
}
cout << score << endl;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while (T--)
solve();
return 0;
}
|
// Name: Baseball Simulation
// Level: 1
// Category: やるだけ
// Note:
/**
* 仕様のとおりに実装する。
*
* オーダーは O(E)。
* ただし、Eはイベントの個数。
*/
#include <iostream>
#include <string>
using namespace std;
bool solve() {
int out = 0;
int b1 = 0, b2 = 0, b3 = 0;
int score = 0;
while (out < 3) {
string event;
cin >> event;
if (event == "HIT") {
if (b3)
++score;
b3 = b2;
b2 = b1;
b1 = 1;
} else if (event == "HOMERUN") {
score += b1 + b2 + b3 + 1;
b1 = b2 = b3 = 0;
} else if (event == "OUT") {
++out;
}
}
cout << score << endl;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while (T--)
solve();
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107]]
| 1
| 177
| 2
|
#include <array>
#include <iostream>
class Baseball {
private:
int out_count;
std::array<int, 4> runner; // first second third home
// runner:1 no:0 home:point
public:
Baseball() {
out_count = 0;
for (int i = 0; i < 4; ++i)
runner[i] = 0;
}
void ining() {
while (out_count != 3) {
std::string str;
std::cin >> str;
if (str == "HIT")
hit();
else if (str == "OUT")
out();
else if (str == "HOMERUN")
homerun();
}
std::cout << runner[3] << std::endl;
return;
}
void hit() {
for (int i = 0; i < 4; ++i) {
if (runner[i] == 0) {
runner[i] = 1;
return;
}
if (i == 3)
++runner[i];
}
}
void out() { ++out_count; }
void homerun() {
for (int i = 0; i < 4; ++i) {
if (runner[i] == 1) {
++runner[3];
runner[i] = 0;
}
}
++runner[3];
}
};
int main() {
int n;
std::cin >> n;
for (int k = 0; k < n; ++k) {
Baseball game;
game.ining();
}
return 0;
}
|
#include <array>
#include <iostream>
class Baseball {
private:
int out_count;
std::array<int, 4> runner; // first second third home
// runner:1 no:0 home:point
public:
Baseball() {
out_count = 0;
for (int i = 0; i < 4; ++i)
runner[i] = 0;
}
void ining() {
while (out_count != 3) {
std::string str;
std::cin >> str;
if (str == "HIT")
hit();
else if (str == "OUT")
out();
else if (str == "HOMERUN")
homerun();
}
std::cout << runner[3] << std::endl;
return;
}
void hit() {
for (int i = 0; i < 4; ++i) {
if (runner[i] == 0) {
runner[i] = 1;
return;
}
if (i == 3)
++runner[i];
}
}
void out() { ++out_count; }
void homerun() {
for (int i = 0; i < 3; ++i) {
if (runner[i] == 1) {
++runner[3];
runner[i] = 0;
}
}
++runner[3];
}
};
int main() {
int n;
std::cin >> n;
for (int k = 0; k < n; ++k) {
Baseball game;
game.ining();
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 294
| 2
|
#include <iostream>
#include <string>
class Baseball {
private:
int out;
int runner;
int point;
public:
void init();
int get_out();
int get_point();
void event_hit();
void event_homerun();
void event_out();
};
void Baseball::init() {
out = 0;
runner = 0;
point = 0;
}
int Baseball::get_out() { return out; }
int Baseball::get_point() { return point; }
void Baseball::event_hit() {
if (runner == 3) {
++point;
} else {
++runner;
}
}
void Baseball::event_homerun() { point += ++runner; }
void Baseball::event_out() { ++out; }
int main(void) {
int num;
std::cin >> num;
std::string event;
Baseball base;
base.init();
for (int i = 0; i < num; ++i) {
while (base.get_out() < 3) {
std::cin >> event;
if (event == "OUT") {
base.event_out();
} else if (event == "HIT") {
base.event_hit();
} else if (event == "HOMERUN") {
base.event_homerun();
}
}
std::cout << base.get_point() << std::endl;
base.init();
}
return 0;
}
|
#include <iostream>
#include <string>
class Baseball {
private:
int out;
int runner;
int point;
public:
void init();
int get_out();
int get_point();
void event_hit();
void event_homerun();
void event_out();
};
void Baseball::init() {
out = 0;
runner = 0;
point = 0;
}
int Baseball::get_out() { return out; }
int Baseball::get_point() { return point; }
void Baseball::event_hit() {
if (runner == 3) {
++point;
} else {
++runner;
}
}
void Baseball::event_homerun() {
point += ++runner;
runner = 0;
}
void Baseball::event_out() { ++out; }
int main(void) {
int num;
std::cin >> num;
std::string event;
Baseball base;
base.init();
for (int i = 0; i < num; ++i) {
while (base.get_out() < 3) {
std::cin >> event;
if (event == "OUT") {
base.event_out();
} else if (event == "HIT") {
base.event_hit();
} else if (event == "HOMERUN") {
base.event_homerun();
}
}
std::cout << base.get_point() << std::endl;
base.init();
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
| 1
| 280
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define PI 4 * atan(1)
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
bool base[3] = {false};
int point = 0, out = 0;
while (1) {
char s[8];
cin >> s;
if (strcmp(s, "HIT") == 0) {
if (base[2] == true) {
point += 1;
base[2] = false;
}
if (base[1] == true) {
base[1] = false;
base[2] = true;
}
if (base[0] == true) {
base[0] = false;
base[1] = true;
}
base[0] = true;
}
if (strcmp(s, "OUT") == 0) {
out++;
if (out == 3)
break;
}
if (strcmp(s, "HOMERUN") == 0) {
for (int j = 0; j < 3; j++) {
if (base[i] == true) {
base[i] = false;
point++;
}
}
point++;
}
}
cout << point << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define PI 4 * atan(1)
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
bool base[3] = {false};
int point = 0, out = 0;
while (1) {
char s[8];
cin >> s;
if (strcmp(s, "HIT") == 0) {
if (base[2] == true) {
point += 1;
base[2] = false;
}
if (base[1] == true) {
base[1] = false;
base[2] = true;
}
if (base[0] == true) {
base[0] = false;
base[1] = true;
}
base[0] = true;
}
if (strcmp(s, "OUT") == 0) {
out++;
if (out == 3)
break;
}
if (strcmp(s, "HOMERUN") == 0) {
for (int j = 0; j < 3; j++) {
if (base[j] == true) {
// cout << "base[" << i << "]" << endl;
base[j] = false;
point++;
}
}
point++;
// cout << "point:" << point << endl;
}
}
cout << point << endl;
}
}
|
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
| 1
| 272
| 4
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int inning_num;
cin >> inning_num;
for (int i = 0; i < inning_num; i++) {
int out = 0;
unsigned char state = 0;
int score = 0;
while (out != 3) {
string in;
cin >> in;
if (in == "OUT") {
state &= 0;
out++;
} else if (in == "HIT") {
state <<= 1;
state |= 0x0001;
} else if (in == "HOMERUN") {
state <<= 1;
state |= 0x0001;
state <<= 3;
}
for (unsigned char j = (1 << 3); j; j <<= 1) {
if (state & j) {
score++;
state &= ~j;
}
}
}
cout << score << "\n";
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int inning_num;
cin >> inning_num;
for (int i = 0; i < inning_num; i++) {
int out = 0;
unsigned char state = 0;
int score = 0;
while (out != 3) {
string in;
cin >> in;
if (in == "OUT") {
out++;
} else if (in == "HIT") {
state <<= 1;
state |= 0x0001;
} else if (in == "HOMERUN") {
state <<= 1;
state |= 0x0001;
state <<= 3;
}
for (unsigned char j = (1 << 3); j; j <<= 1) {
if (state & j) {
score++;
state &= ~j;
}
}
}
cout << score << "\n";
}
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 161], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["-", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 171
| 4
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int combi[100000][3] = {0}, m = 0;
int input, price[100000] = {0}, weight;
int a, b, c, a1, b1, c1;
while (cin >> input) {
if (input == 0)
break;
for (int i = 0; i < 26; i++) { // generate combination of weight over input
for (int j = 0; j < 17; j++) {
for (int k = 0; k < 11; k++) {
weight = 200 * i + 300 * j + 500 * k;
// cout << weight << " ";
if (input <= weight) {
combi[m][0] = i;
combi[m][1] = j;
combi[m][2] = k;
// cout << combi[m][0] << " " << combi[m][1] << " " << combi[m][2]
// << endl;
m++;
}
}
}
}
for (int i = 0; i < m; i++) { // calculate price[i] from combi[i]
a = combi[i][0] / 5; // sale
a1 = combi[i][0] - a * 5; // not sale
b = combi[i][1] / 4; // sale
b1 = combi[i][1] - b * 4; // not sale
c = combi[i][2] / 3; // sale
c1 = combi[i][2] - c * 3; // not sale
price[i] =
1520 * a + 380 * a1 + 1870 * b + 550 * b1 + 2244 * c + 850 * c1;
// cout << price[i] << endl;
}
sort(price, price + m);
cout << price[0] << endl;
m = 0;
int price[100000] = {0};
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int combi[100000][3] = {0}, m = 0;
int input, price[100000] = {0}, weight;
int a, b, c, a1, b1, c1;
while (cin >> input) {
if (input == 0)
break;
for (int i = 0; i < 26; i++) { // generate combination of weight over input
for (int j = 0; j < 17; j++) {
for (int k = 0; k < 11; k++) {
weight = 200 * i + 300 * j + 500 * k;
// cout << weight << " ";
if (input == weight) {
combi[m][0] = i;
combi[m][1] = j;
combi[m][2] = k;
// cout << combi[m][0] << " " << combi[m][1] << " " << combi[m][2]
// << endl;
m++;
}
}
}
}
for (int i = 0; i < m; i++) { // calculate price[i] from combi[i]
a = combi[i][0] / 5; // sale
a1 = combi[i][0] - a * 5; // not sale
b = combi[i][1] / 4; // sale
b1 = combi[i][1] - b * 4; // not sale
c = combi[i][2] / 3; // sale
c1 = combi[i][2] - c * 3; // not sale
price[i] =
1520 * a + 380 * a1 + 1870 * b + 550 * b1 + 2244 * c + 850 * c1;
// cout << price[i] << endl;
}
sort(price, price + m);
cout << price[0] << endl;
m = 0;
int price[100000] = {0};
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
| 1
| 344
| 2
|
// 32
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
for (int n; cin >> n, n;) {
int mc = 1 << 30;
for (int a = 0; a * 200 < n + 200; a++) {
for (int b = 0; a * 200 + b * 300 < n + 300; b++) {
for (int c = 0; a * 200 + b * 300 + c * 500 < n + 500; c++) {
if (a * 200 + b * 300 + c * 500 >= n) {
int cst =
a * 380 + b * 550 + c * 850 - (a / 5) * 380 * 20 * 5 / 100 -
(b / 4) * 550 * 15 * 4 / 100 - (c / 3) * 850 * 12 * 3 / 100;
mc = min(cst, mc);
}
}
}
}
cout << mc << endl;
}
return 0;
}
|
// 32
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
for (int n; cin >> n, n;) {
int mc = 1 << 30;
for (int a = 0; a * 200 < n + 200; a++) {
for (int b = 0; a * 200 + b * 300 < n + 300; b++) {
for (int c = 0; a * 200 + b * 300 + c * 500 < n + 500; c++) {
if (a * 200 + b * 300 + c * 500 == n) {
int cst =
a * 380 + b * 550 + c * 850 - (a / 5) * 380 * 20 * 5 / 100 -
(b / 4) * 550 * 15 * 4 / 100 - (c / 3) * 850 * 12 * 3 / 100;
mc = min(cst, mc);
}
}
}
}
cout << mc << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
| 1
| 201
| 2
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define INF (1 << 29)
int N;
bool ok(int a, int b, int c) {
if (a * 200 + b * 300 + c * 500 >= N)
return true;
return false;
}
int calc(int a, int b, int c) {
return a * 380 - (a / 5) * 380 + b * 550 - (b / 4) * 330 + c * 850 -
(c / 3) * 306;
}
int main() {
while (scanf("%d", &N), N) {
int res = INF;
for (int a = 0; a < 251; a++) {
for (int b = 0; b < 200; b++) {
for (int c = 0; c < 101; c++) {
if (ok(a, b, c))
res = min(res, calc(a, b, c));
}
}
}
printf("%d\n", res);
}
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define INF (1 << 29)
int N;
bool ok(int a, int b, int c) {
if (a * 200 + b * 300 + c * 500 == N)
return true;
return false;
}
int calc(int a, int b, int c) {
return a * 380 - (a / 5) * 380 + b * 550 - (b / 4) * 330 + c * 850 -
(c / 3) * 306;
}
int main() {
while (scanf("%d", &N), N) {
int res = INF;
for (int a = 0; a < 251; a++) {
for (int b = 0; b < 200; b++) {
for (int c = 0; c < 101; c++) {
if (ok(a, b, c))
res = min(res, calc(a, b, c));
}
}
}
printf("%d\n", res);
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
| 1
| 221
| 2
|
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
public static Scanner sc;
public static ArrayList<Integer> list;
public static void main(String[] args) throws Exception {
sc = new Scanner(System.in);
while (sc.hasNext()) {
list = new ArrayList<>();
list.add(sc.nextInt());
list.add(sc.nextInt());
list.add(sc.nextInt());
if (list.get(0) == 0 && list.get(1) == 0 && list.get(2) == 0) {
break;
}
Collections.sort(list);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
double r = sc.nextDouble();
double d =
Math.sqrt(Math.pow(list.get(0), 2) + Math.pow(list.get(1), 2));
// System.out.println(r + " " + d);
if (r * 2 >= d) {
System.out.println("OK");
} else {
System.out.println("NA");
}
}
}
}
}
|
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
public static Scanner sc;
public static ArrayList<Integer> list;
public static void main(String[] args) throws Exception {
sc = new Scanner(System.in);
while (sc.hasNext()) {
list = new ArrayList<>();
list.add(sc.nextInt());
list.add(sc.nextInt());
list.add(sc.nextInt());
if (list.get(0) == 0 && list.get(1) == 0 && list.get(2) == 0) {
break;
}
Collections.sort(list);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
double r = sc.nextDouble();
double d =
Math.sqrt(Math.pow(list.get(0), 2) + Math.pow(list.get(1), 2));
// System.out.println(r + " " + d);
if (r * 2 > d) {
System.out.println("OK");
} else {
System.out.println("NA");
}
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 47]]
| 3
| 268
| 2
|
#include <stdio.h>
#define sqr(x) ((x) * (x))
void swap(int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
int main(void) {
int i, s[3], n, r;
while (1) {
scanf("%d %d %d", &s[0], &s[1], &s[2]);
if (!s[0] && !s[1] && !s[2])
break;
if (s[0] > s[1])
swap(&s[0], &s[1]);
if (s[1] > s[2])
swap(&s[1], &s[2]);
if (s[0] > s[1])
swap(&s[0], &s[1]);
// printf("%d %d %d\n",s[0],s[1],s[2]);
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &r);
if (sqr(s[0] / 2) + sqr(s[1] / 2) < sqr(r)) {
puts("OK");
} else {
puts("NA");
}
}
}
return 0;
}
|
#include <stdio.h>
#define sqr(x) ((x) * (x))
void swap(int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
int main(void) {
int i, s[3], n, r;
while (1) {
scanf("%d %d %d", &s[0], &s[1], &s[2]);
if (!s[0] && !s[1] && !s[2])
break;
if (s[0] > s[1])
swap(&s[0], &s[1]);
if (s[1] > s[2])
swap(&s[1], &s[2]);
if (s[0] > s[1])
swap(&s[0], &s[1]);
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &r);
if (sqr(s[0]) + sqr(s[1]) < sqr(2 * r)) {
puts("OK");
} else {
puts("NA");
}
}
}
return 0;
}
|
[["-", 31, 16, 31, 2, 3, 4, 0, 16, 17, 85], ["-", 31, 16, 31, 2, 3, 4, 0, 16, 12, 13], ["-", 31, 16, 12, 2, 3, 4, 0, 16, 17, 85], ["-", 31, 16, 12, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 16, 12, 2, 3, 4, 0, 16, 31, 13], ["+", 0, 16, 12, 2, 3, 4, 0, 16, 17, 48]]
| 0
| 276
| 6
|
#include <stdio.h>
void swap(int *a, int *b) {
*a += *b;
*b = *a - *b;
*a -= *b;
}
int main(void) {
int x, y, z;
int n;
int r;
int i;
while (1) {
scanf("%d %d %d", &x, &y, &z);
if (x == 0 && y == 0 && z == 0) {
break;
}
if (x < y) {
swap(&x, &y);
}
if (y > z) {
swap(&y, &z);
}
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &r);
if (x * x + y * y < 4 * r * r) {
printf("OK\n");
} else {
printf("NA\n");
}
}
}
return (0);
}
|
#include <stdio.h>
void swap(int *a, int *b) {
*a += *b;
*b = *a - *b;
*a -= *b;
}
int main(void) {
int x, y, z;
int n;
int r;
int i;
while (1) {
scanf("%d %d %d", &x, &y, &z);
if (x == 0 && y == 0 && z == 0) {
break;
}
if (x > y) {
swap(&x, &y);
}
if (y > z) {
swap(&y, &z);
}
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &r);
if (x * x + y * y < 4 * r * r) {
printf("OK\n");
} else {
printf("NA\n");
}
}
}
return (0);
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47]]
| 0
| 210
| 2
|
#include <math.h>
#include <stdio.h>
int main(void) {
int x, y, z;
for (;;) {
scanf("%d%d%d", &x, &y, &z);
if (x == y == z == 0)
break;
int n;
scanf("%d", &n);
int i;
int r[10000];
for (i = 0; i < n; i++) { //入力
scanf("%d", &r[i]);
}
double a, b, a2, b2, c2, csub;
if (x >= y && x >= z)
a = y, b = z;
else if (y >= x && y >= z)
a = x, b = z;
else if (z >= x && z >= y)
a = x, b = y;
a2 = a / 2;
b2 = b / 2;
csub = a2 * a2 + b2 * b2;
c2 = sqrt(csub);
// printf("%lf\n",c2);
for (i = 0; i < n; i++) { //計算
if (c2 < r[i])
printf("OK\n", r[i]);
else
printf("NA\n", r[i]);
}
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
int x, y, z;
for (;;) {
scanf("%d%d%d", &x, &y, &z);
if (x == 0)
break;
int n;
scanf("%d", &n);
int i;
int r[10000];
for (i = 0; i < n; i++) { //入力
scanf("%d", &r[i]);
}
double a, b, a2, b2, c2, csub;
if (x >= y && x >= z)
a = y, b = z;
else if (y >= x && y >= z)
a = x, b = z;
else if (z >= x && z >= y)
a = x, b = y;
a2 = a / 2;
b2 = b / 2;
csub = a2 * a2 + b2 * b2;
c2 = sqrt(csub);
// printf("%lf\n",c2);
for (i = 0; i < n; i++) { //計算
if (c2 < r[i])
printf("OK\n", r[i]);
else
printf("NA\n", r[i]);
}
}
return 0;
}
|
[["-", 15, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 23, 0, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60]]
| 0
| 258
| 4
|
#include <iostream>
using namespace std;
int main() {
int n, r, d, w, h, x;
while (1) {
cin >> d >> w >> h;
if (d + w + h == 0)
return 0;
if (d <= h && w <= h)
x = d * d + w * w;
else if (d <= w && h <= w)
x = d * d + h * h;
else if (w <= d && h <= d)
x = w * w + h * h;
cout << x;
cin >> n;
for (int lop = 0; lop < n; lop++) {
cin >> r;
if (4 * r * r > x)
cout << "OK\n";
else
cout << "NA\n";
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, r, d, w, h, x;
while (1) {
cin >> d >> w >> h;
if (d + w + h == 0)
return 0;
if (d <= h && w <= h)
x = d * d + w * w;
else if (d <= w && h <= w)
x = d * d + h * h;
else if (w <= d && h <= d)
x = w * w + h * h;
cin >> n;
for (int lop = 0; lop < n; lop++) {
cin >> r;
if (4 * r * r > x)
cout << "OK\n";
else
cout << "NA\n";
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 170
| 4
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
vector<int> a(3);
while (true) {
cin >> a[0] >> a[1] >> a[2];
if (a[0] == 0 && a[1] == 0 && a[2] == 0)
break;
sort(a.begin(), a.end());
int d = a[0] * a[0] + a[1] * a[1];
int n;
cin >> n;
rep(i, n) {
int r;
cin >> r;
if (d < (r * 2) * (r * 2)) {
cout << "OK" << endl;
} else {
cout << "NO" << endl;
}
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
vector<int> a(3);
while (true) {
cin >> a[0] >> a[1] >> a[2];
if (a[0] == 0 && a[1] == 0 && a[2] == 0)
break;
sort(a.begin(), a.end());
int d = a[0] * a[0] + a[1] * a[1];
int n;
cin >> n;
rep(i, n) {
int r;
cin >> r;
if (d < (r * 2) * (r * 2)) {
cout << "OK" << endl;
} else {
cout << "NA" << endl;
}
}
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 193
| 2
|
#include <math.h>
#include <stdio.h>
int main() {
int x, y, z, N, r;
int n[1001] = {};
while (1) {
scanf("%d %d %d", &n[0], &n[1], &n[2]);
if (n[0] == 0 && n[1] == 0 && n[2] == 0)
break;
for (int i = 0; i < 3; i++)
for (int j = 2; j > i; j--)
if (n[j - 1] > n[j]) {
int t = n[j];
n[j] = n[j - 1];
n[j - 1] = t;
}
// printf("%d %d %d\n",n[0],n[1],n[2]);
double rad = atan2((double)(n[1]), (double)(n[0]));
// rad=rad*3.141592/180;
// printf("%lf\n",rad);
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &r);
// printf("%d %lf\n",n[1],(r*2*sin(rad)));
if (n[1] >= (int)(r * 2 * sin(rad)))
printf("NA\n");
else
printf("OK\n");
}
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int x, y, z, N, r;
int n[1001] = {};
while (1) {
scanf("%d %d %d", &n[0], &n[1], &n[2]);
if (n[0] == 0 && n[1] == 0 && n[2] == 0)
break;
for (int i = 0; i < 3; i++)
for (int j = 2; j > i; j--)
if (n[j - 1] > n[j]) {
int t = n[j];
n[j] = n[j - 1];
n[j - 1] = t;
}
// printf("%d %d %d\n",n[0],n[1],n[2]);
double rad = atan2((double)(n[1]), (double)(n[0]));
// rad=rad*3.141592/180;
// printf("%lf\n",rad);
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &r);
// printf("%d %lf\n",n[1],(r*2*sin(rad)));
if (n[1] >= (r * 2 * sin(rad)))
printf("NA\n");
else
printf("OK\n");
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 12, 74, 39, 77, 39, 40], ["-", 0, 57, 15, 339, 51, 16, 12, 74, 0, 25], ["-", 15, 339, 51, 16, 12, 74, 51, 23, 0, 24]]
| 1
| 266
| 3
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define rp(a) while (a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main() {
vector<double> a(3);
while (cin >> a[0] >> a[1] >> a[2], a[0]) {
sort(all(a));
double r = hypot(a[0], a[1]) / 2;
int n;
cin >> n;
rp(n) {
int m;
cin >> m;
if (m > r)
cout << "OK" << endl;
else
cout << "NG" << endl;
}
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define rp(a) while (a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main() {
vector<double> a(3);
while (cin >> a[0] >> a[1] >> a[2], a[0]) {
sort(all(a));
double r = hypot(a[0], a[1]) / 2;
int n;
cin >> n;
rp(n) {
int m;
cin >> m;
if (m > r)
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 198
| 2
|
#include <cmath>
#include <iostream>
using namespace std;
double h[10000];
int main() {
int x;
int y;
int z;
int n;
double xy;
double yz;
double zx;
while (true) {
cin >> x >> y >> z;
if (!x && !y && !z) {
break;
}
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
xy = sqrt(x * x + y * y);
yz = sqrt(y * y + z * z);
zx = sqrt(z * z + x * x);
for (int i = 0; i < n; ++i) {
bool flag = false;
if (xy <= h[i] * 2 || yz <= h[i] * 2 || zx <= h[i] * 2) {
flag = true;
}
if (flag) {
cout << "OK" << endl;
} else {
cout << "NA" << endl;
}
}
}
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
double h[10000];
int main() {
int x;
int y;
int z;
int n;
double xy;
double yz;
double zx;
while (true) {
cin >> x >> y >> z;
if (!x && !y && !z) {
break;
}
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
xy = sqrt(x * x + y * y);
yz = sqrt(y * y + z * z);
zx = sqrt(z * z + x * x);
for (int i = 0; i < n; ++i) {
bool flag = false;
if (xy < h[i] * 2 || yz < h[i] * 2 || zx < h[i] * 2) {
flag = true;
}
if (flag) {
cout << "OK" << endl;
} else {
cout << "NA" << endl;
}
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 16, 31, 16, 17, 19], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 17, 18], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 19], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 18], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18]]
| 1
| 220
| 6
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int tate, yoko, takasa, mn, md;
int n;
while (cin >> tate >> yoko >> takasa, tate || yoko || takasa) {
cin >> n;
int *r = new int[n];
mn = min(min(tate, yoko), takasa);
if (tate >= yoko) {
if (yoko >= takasa) {
md = yoko;
} else if (yoko < takasa) {
if (tate >= takasa)
md = takasa;
else if (tate < takasa)
md = tate;
}
} else if (tate < yoko) {
if (tate >= takasa) {
md = tate;
} else if (tate < takasa) {
if (yoko >= takasa)
md = takasa;
else if (yoko < takasa)
md = yoko;
}
}
for (int i = 0; i < n; ++i) {
cin >> r[i];
cout << ((r[i] * r[i] * 4 > mn * mn + md * md) ? "OK" : "NA") << endl;
delete[] r;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int tate, yoko, takasa, mn, md;
int n;
while (cin >> tate >> yoko >> takasa, tate || yoko || takasa) {
cin >> n;
int *r = new int[n];
mn = min(min(tate, yoko), takasa);
if (tate >= yoko) {
if (yoko >= takasa) {
md = yoko;
} else if (yoko < takasa) {
if (tate >= takasa)
md = takasa;
else if (tate < takasa)
md = tate;
}
} else if (tate < yoko) {
if (tate >= takasa) {
md = tate;
} else if (tate < takasa) {
if (yoko >= takasa)
md = takasa;
else if (yoko < takasa)
md = yoko;
}
}
for (int i = 0; i < n; ++i) {
cin >> r[i];
cout << ((r[i] * r[i] * 4 > mn * mn + md * md) ? "OK" : "NA") << endl;
}
delete[] r;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 7, 8, 9, 0, 46], ["-", 0, 52, 8, 9, 0, 7, 8, 9, 0, 46]]
| 1
| 254
| 2
|
#include <cstdio>
#include <iostream>
using namespace std;
int mini_1(int i, int j, int k) {
if (i <= j && i <= k) {
return i;
} else if (j <= i && j <= k) {
return j;
} else {
return k;
}
}
int mini_2(int i, int j, int k) {
if (i <= j && j <= k) {
return j;
} else if (k <= j && j <= i) {
return j;
} else if (i <= j && k <= i) {
return i;
} else if (j <= i && i <= k) {
return i;
} else {
return k;
}
}
int main() {
int a, b, c, n, min1, min2, r;
cin >> a >> b >> c;
while (a != 0 || b != 0 || c != 0) {
min1 = mini_1(a, b, c);
min2 = mini_2(a, b, c);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> r;
if (4 * r * r > min1 * min1 + min2 * min2) {
printf("OK\n");
} else {
printf("NG\n");
}
}
cin >> a >> b >> c;
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int mini_1(int i, int j, int k) {
if (i <= j && i <= k) {
return i;
} else if (j <= i && j <= k) {
return j;
} else {
return k;
}
}
int mini_2(int i, int j, int k) {
if (i <= j && j <= k) {
return j;
} else if (k <= j && j <= i) {
return j;
} else if (i <= j && k <= i) {
return i;
} else if (j <= i && i <= k) {
return i;
} else {
return k;
}
}
int main() {
int a, b, c, n, min1, min2, r;
cin >> a >> b >> c;
while (a != 0 || b != 0 || c != 0) {
min1 = mini_1(a, b, c);
min2 = mini_2(a, b, c);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> r;
if (4 * r * r > min1 * min1 + min2 * min2) {
printf("OK\n");
} else {
printf("NA\n");
}
}
cin >> a >> b >> c;
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 281
| 2
|
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#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 ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct UnionFind {
vector<int> v;
UnionFind(int n) : v(n) {
for (int i = 0; i < n; i++)
v[i] = i;
}
int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
void unite(int x, int y) { v[find(x)] = find(y); }
};
int main() {
int d[3];
while (cin >> d[0] >> d[1] >> d[2], d[0] | d[1] | d[2]) {
vector<int> dx(3);
REP(i, 3) { dx[i] = d[i] * d[i] + d[(i + 1) % 3] * d[(i + 1) % 3]; }
SORT(dx);
int n;
cin >> n;
vector<int> s(n);
REP(i, n) { cin >> s[i]; }
REP(i, n) {
if (dx[1] < (s[i] * 2) * (s[i] * 2))
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
}
|
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#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 ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct UnionFind {
vector<int> v;
UnionFind(int n) : v(n) {
for (int i = 0; i < n; i++)
v[i] = i;
}
int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
void unite(int x, int y) { v[find(x)] = find(y); }
};
int main() {
int d[3];
while (cin >> d[0] >> d[1] >> d[2], d[0] | d[1] | d[2]) {
vector<int> dx(3);
REP(i, 3) { dx[i] = d[i] * d[i] + d[(i + 1) % 3] * d[(i + 1) % 3]; }
SORT(dx);
int n;
cin >> n;
vector<int> s(n);
REP(i, n) { cin >> s[i]; }
REP(i, n) {
if (dx[0] < (s[i] * 2) * (s[i] * 2))
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
}
|
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13]]
| 1
| 494
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<int> side(3); // ???, ?¨?, ??????
int n; // ??\??£????????°
int rad; // ??\??£?????????
int diagonal; // ????§?????????????
string ans[2] = {"NG", "OK"}; // ??????
while (1) {
cin >> side[0] >> side[1] >> side[2];
if (side[0] + side[1] + side[2] == 0)
break;
// ????§????????¨????
{
sort(side.begin(), side.end());
diagonal = sqrt(pow((double)side[0], 2) + pow((double)side[1], 2));
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> rad;
cout << (rad * 2 > diagonal ? "OK" : "NG") << endl;
}
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<int> side(3); // ???, ?¨?, ??????
int n; // ??\??£????????°
int rad; // ??\??£?????????
int diagonal; // ????§?????????????
string ans[2] = {"NG", "OK"}; // ??????
while (1) {
cin >> side[0] >> side[1] >> side[2];
if (side[0] + side[1] + side[2] == 0)
break;
// ????§????????¨????
{
sort(side.begin(), side.end());
diagonal = sqrt(pow((double)side[0], 2) + pow((double)side[1], 2));
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> rad;
cout << (rad * 2 > diagonal ? "OK" : "NA") << endl;
}
}
}
|
[["-", 31, 16, 12, 23, 0, 41, 75, 5, 0, 6], ["+", 31, 16, 12, 23, 0, 41, 75, 5, 0, 6]]
| 1
| 196
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int m[3];
int n;
while (cin >> m[0] >> m[1] >> m[2], m[0] || m[1] || m[2]) {
sort(m, m + 3);
int S = m[0] * m[0] + m[1] * m[1];
int n, num;
cin >> n;
while (n--) {
cin >> num;
double size = num * num * M_PI;
cout << (S < size ? "OK" : "NA") << endl;
}
}
return (0);
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int m[3];
int n;
while (cin >> m[0] >> m[1] >> m[2], m[0] || m[1] || m[2]) {
sort(m, m + 3);
int S = m[0] * m[0] + m[1] * m[1];
int n, num;
cin >> n;
while (n--) {
cin >> num;
int size = num * num * 4;
cout << (S < size ? "OK" : "NA") << endl;
}
}
return (0);
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 145
| 4
|
#include <math.h>
#include <stdio.h>
#include <string.h>
int main(void) {
long long int a, s, d, f, g[100000], h, i, j, z, x, c, q[4];
while (1) {
scanf("%lld %lld %lld", &a, &s, &d);
if (a == 0 && s == 0 && d == 0)
break;
scanf("%lld", &f);
for (i = 0; i < f; i++)
scanf("%lld", &g[i]);
q[0] = a * a + s * s;
q[1] = a * a + d * d;
q[2] = s * s + d * d;
for (i = 0; i < f; i++) {
j = (g[i] * 2) * (g[i] * 2);
if (j <= q[0] && j <= q[1] && j <= q[1])
printf("NA\n");
else
printf("OK\n");
}
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
#include <string.h>
int main(void) {
long long int a, s, d, f, g[100000], h, i, j, z, x, c, q[4];
while (1) {
scanf("%lld %lld %lld", &a, &s, &d);
if (a == 0 && s == 0 && d == 0)
break;
scanf("%lld", &f);
for (i = 0; i < f; i++)
scanf("%lld", &g[i]);
q[0] = a * a + s * s;
q[1] = a * a + d * d;
q[2] = s * s + d * d;
for (i = 0; i < f; i++) {
j = (g[i] * 2) * (g[i] * 2);
if (j <= q[0] && j <= q[1] && j <= q[2])
printf("NA\n");
else
printf("OK\n");
}
}
return 0;
}
|
[["-", 51, 16, 12, 16, 12, 69, 341, 342, 0, 13], ["+", 51, 16, 12, 16, 12, 69, 341, 342, 0, 13]]
| 1
| 237
| 2
|
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on
void solve() {
int a, b, c;
while (cin >> a >> b >> c, a) {
int n;
cin >> n;
int x = min({a * a + b * b, b * b + a * a, c * c + a * a});
while (n--) {
int r;
cin >> r;
cout << (x < 4 * r * r ? "OK" : "NA") << endl;
}
}
}
|
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on
void solve() {
int a, b, c;
while (cin >> a >> b >> c, a) {
int n;
cin >> n;
int x = min({a * a + b * b, b * b + c * c, c * c + a * a});
while (n--) {
int r;
cin >> r;
cout << (x < 4 * r * r ? "OK" : "NA") << endl;
}
}
}
|
[["-", 3, 4, 0, 83, 0, 16, 12, 16, 31, 22], ["+", 3, 4, 0, 83, 0, 16, 12, 16, 31, 22], ["-", 3, 4, 0, 83, 0, 16, 12, 16, 12, 22], ["+", 3, 4, 0, 83, 0, 16, 12, 16, 12, 22]]
| 1
| 429
| 4
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a[3];
while (cin >> a[0] >> a[1] >> a[2]) {
if (a[0] == 0 && a[1] == 0 && a[3] == 0)
break;
sort(a, a + 3);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int r;
cin >> r;
if ((a[0] * a[0] + a[1] * a[1]) < r * r * 4)
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a[3];
while (cin >> a[0] >> a[1] >> a[2]) {
if (a[0] == 0 && a[1] == 0 && a[2] == 0)
break;
sort(a, a + 3);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int r;
cin >> r;
if ((a[0] * a[0] + a[1] * a[1]) < r * r * 4)
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
return 0;
}
|
[["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 13], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 13]]
| 1
| 155
| 2
|
// 2011/01/14 Tazoe
#include <iostream>
using namespace std;
void ABC_sort(int &A, int &B, int &C) {
int tmp[3] = {A, B, C};
for (int i = 0; i < 2; i++)
for (int j = i + 1; j < 3; j++)
if (tmp[i] > tmp[j]) {
int swp = tmp[i];
tmp[i] = tmp[j];
tmp[j] = swp;
}
A = tmp[0];
B = tmp[1];
C = tmp[2];
}
int main() {
while (true) {
int A, B, C;
cin >> A >> B >> C;
if (A == 0 && B == 0 && C == 0)
break;
ABC_sort(A, B, C);
int D = A * A + C * C;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int R;
cin >> R;
if (D < 4 * R * R)
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
return 0;
}
|
// 2011/01/14 Tazoe
#include <iostream>
using namespace std;
void ABC_sort(int &A, int &B, int &C) {
int tmp[3] = {A, B, C};
for (int i = 0; i < 2; i++)
for (int j = i + 1; j < 3; j++)
if (tmp[i] > tmp[j]) {
int swp = tmp[i];
tmp[i] = tmp[j];
tmp[j] = swp;
}
A = tmp[0];
B = tmp[1];
C = tmp[2];
}
int main() {
while (true) {
int A, B, C;
cin >> A >> B >> C;
if (A == 0 && B == 0 && C == 0)
break;
ABC_sort(A, B, C);
int D = A * A + B * B;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int R;
cin >> R;
if (D < 4 * R * R)
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 16, 12, 16, 31, 22], ["+", 0, 43, 49, 50, 51, 16, 12, 16, 31, 22], ["-", 0, 43, 49, 50, 51, 16, 12, 16, 12, 22], ["+", 0, 43, 49, 50, 51, 16, 12, 16, 12, 22]]
| 1
| 251
| 4
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
//#define M(a,b) a<b?a:b
int main() {
int a, b, c, n, r;
for (; scanf("%d%d%d", &a, &b, &c), a | b | c;) {
for (scanf("%d", &n); n--;) {
scanf("%d", &r);
puts((2. * r <=
std::min(std::min(sqrt(a * a + b * b), sqrt(b * b + c * c)),
sqrt(c * c + a * a)))
? "OK"
: "NA");
}
}
}
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
//#define M(a,b) a<b?a:b
int main() {
int a, b, c, n, r;
for (; scanf("%d%d%d", &a, &b, &c), a | b | c;) {
for (scanf("%d", &n); n--;) {
scanf("%d", &r);
puts((2 * r > std::min(std::min(sqrt(a * a + b * b), sqrt(b * b + c * c)),
sqrt(c * c + a * a)))
? "OK"
: "NA");
}
}
}
|
[["-", 0, 41, 15, 23, 0, 16, 31, 16, 31, 13], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 31, 13], ["-", 3, 4, 0, 41, 15, 23, 0, 16, 17, 19], ["+", 3, 4, 0, 41, 15, 23, 0, 16, 17, 47]]
| 1
| 140
| 4
|
#include <math.h>
#include <stdio.h>
#define M(a, b) a < b ? a : b
int main() {
for (int a, b, c, n, r; scanf("%d%d%d", &a, &b, &c), a | b | c;) {
for (scanf("%d", &n); n--;) {
scanf("%d", &r);
puts((2 * r >
M(M(sqrt(a * a + b * b), sqrt(b * b + c * c)), sqrt(c * c + a * a)))
? "OK"
: "NA");
}
}
}
|
#include <math.h>
#include <stdio.h>
#define M(a, b) (a < b ? a : b)
int main() {
for (int a, b, c, n, r; scanf("%d%d%d", &a, &b, &c), a | b | c;) {
for (scanf("%d", &n); n--;) {
scanf("%d", &r);
puts((2 * r >
M(M(sqrt(a * a + b * b), sqrt(b * b + c * c)), sqrt(c * c + a * a)))
? "OK"
: "NA");
}
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59]]
| 1
| 140
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
void solve() {}
int main() {
double a, b, c;
while (cin >> a >> b >> c, a || b || c) {
double len = min(a * a + b * b, min(a * a + c * c, b * b + c * c));
int n;
cin >> n;
rep(i, n) {
double r;
cin >> r;
r *= 2;
if (len > r * r) {
cout << "NA\n";
} else {
cout << "OK\n";
}
}
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
void solve() {}
int main() {
double a, b, c;
while (cin >> a >> b >> c, a || b || c) {
double len = min(a * a + b * b, min(a * a + c * c, b * b + c * c));
int n;
cin >> n;
rep(i, n) {
double r;
cin >> r;
r *= 2;
if (len >= r * r) {
cout << "NA\n";
} else {
cout << "OK\n";
}
}
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 170
| 2
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
double x, y, z;
while (cin >> x >> y >> z) {
double r =
min(sqrt(x * x + y * y), min(sqrt(y * y + z * z), sqrt(z * z + y * y)));
if (!r)
break;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
double R;
cin >> R;
R += R;
if (R >= r)
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
double x, y, z;
while (cin >> x >> y >> z) {
double r =
min(sqrt(x * x + y * y), min(sqrt(y * y + z * z), sqrt(z * z + y * y)));
if (!r)
break;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
double R;
cin >> R;
R += R;
if (R > r)
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 142
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int c[3];
while (cin >> c[0] >> c[1] >> c[2]) {
if (!c[0] && !c[1] && !c[2]) {
break;
}
sort(c, c + 2);
double R = sqrt(pow((double)c[0], 2) + pow((double)c[1], 2));
int n;
cin >> n;
while (n) {
int r;
cin >> r;
cout << (2 * r > R ? "OK" : "NA") << endl;
n--;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int c[3];
while (cin >> c[0] >> c[1] >> c[2]) {
if (!c[0] && !c[1] && !c[2]) {
break;
}
sort(c, c + 3);
double R = sqrt(pow((double)c[0], 2) + pow((double)c[1], 2));
int n;
cin >> n;
while (n) {
int r;
cin >> r;
cout << (2 * r > R ? "OK" : "NA") << endl;
n--;
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 154
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
int n;
while (1) {
// a,b,cの入力
/* char line[100];
fgets(line,sizeof(line),stdin);
sscanf(line,"%d %d %d",&a,&b,&c);
*/
scanf("%d %d %d", &a, &b, &c);
// a=b=c=0 なら終了
if (a == 0 && b == 0 && c == 0) {
break;
}
//対角線の半分を求め、その最大値を求める
double d[3];
d[0] = sqrt(a * a + b * b) / 2;
d[1] = sqrt(b * b + c * c) / 2;
d[2] = sqrt(c * c + a * a) / 2;
double maxd = d[0];
for (int i = 0; i < 2; i++) {
if (maxd < d[i])
maxd = d[i];
}
// nの入力
cin >> n;
// rの入力、判定
for (int i = 0; i < n; i++) {
double r = 0;
cin >> r;
if (maxd < r) {
cout << "OK\n";
} else {
cout << "NA\n";
}
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
int n;
while (1) {
// a,b,cの入力
/* char line[100];
fgets(line,sizeof(line),stdin);
sscanf(line,"%d %d %d",&a,&b,&c);
*/
scanf("%d %d %d", &a, &b, &c);
// a=b=c=0 なら終了
if (a == 0 && b == 0 && c == 0) {
break;
}
//対角線の半分を求め、その最大値を求める
double d[3];
d[0] = sqrt(a * a + b * b) / 2;
d[1] = sqrt(b * b + c * c) / 2;
d[2] = sqrt(c * c + a * a) / 2;
double mind = d[0];
for (int i = 0; i < 2; i++) {
if (mind > d[i])
mind = d[i];
}
// nの入力
cin >> n;
// rの入力、判定
for (int i = 0; i < n; i++) {
double r = 0;
cin >> r;
if (mind < r) {
cout << "OK\n";
} else {
cout << "NA\n";
}
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 49, 22], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 49, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22]]
| 1
| 233
| 10
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
int x, y, z, n;
int sq(int a) { return a * a; }
void solve() {
int a[3] = {x, y, z};
sort(a, a + 3);
int r2 = sq(a[0]) + sq(a[1]);
cin >> n;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
puts((r2 <= 4 * b * b) ? "NA" : "OK");
}
}
int main() {
while (cin >> x >> y >> z, (x || y || z)) {
solve();
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
int x, y, z, n;
ll sq(ll a) { return a * a; }
void solve() {
ll a[3] = {x, y, z};
sort(a, a + 3);
ll r2 = sq(a[0]) + sq(a[1]);
cin >> n;
for (int i = 0; i < n; i++) {
ll b;
cin >> b;
puts((r2 >= 4 * b * b) ? "NA" : "OK");
}
}
int main() {
while (cin >> x >> y >> z, (x || y || z)) {
solve();
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 14, 39, 78], ["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 40], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 39, 78], ["-", 3, 4, 0, 41, 15, 23, 0, 16, 17, 19], ["+", 3, 4, 0, 41, 15, 23, 0, 16, 17, 20]]
| 1
| 230
| 12
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int edge[3];
while (cin >> edge[0] >> edge[1] >> edge[2], edge[0] || edge[1] || edge[2]) {
int n;
cin >> n;
sort(edge, edge + 2);
while (n--) {
int x;
cin >> x;
if (edge[0] * edge[0] + edge[1] * edge[1] < x * x * 4) {
cout << "OK" << endl;
} else {
cout << "NA" << endl;
}
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int edge[3];
while (cin >> edge[0] >> edge[1] >> edge[2], edge[0] || edge[1] || edge[2]) {
int n;
cin >> n;
sort(edge, edge + 3);
while (n--) {
int x;
cin >> x;
if (edge[0] * edge[0] + edge[1] * edge[1] < x * x * 4) {
cout << "OK" << endl;
} else {
cout << "NA" << endl;
}
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 138
| 2
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int p, a, b, c, i, n, x;
while (1) {
scanf("%d %d %d", &a, &b, &c);
if (a == 0)
return 0;
if (a < c) {
p = a;
a = c;
c = a;
}
if (a < b) {
p = a;
a = b;
b = a;
}
double r = sqrt(b * b + c * c);
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &x);
if (r < (double)x * 2)
printf("OK\n");
else
printf("NG\n");
}
}
}
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int p, a, b, c, i, n, x;
while (1) {
scanf("%d %d %d", &a, &b, &c);
if (a == 0)
return 0;
if (a < c) {
p = a;
a = c;
c = a;
}
if (a < b) {
p = a;
a = b;
b = a;
}
double r = sqrt(b * b + c * c);
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &x);
if (r < (double)x * 2)
printf("OK\n");
else
printf("NA\n");
}
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 175
| 2
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c;
while (cin >> a >> b >> c, a + b + c) {
if (a > b) {
swap(a, b);
}
if (b > c) {
swap(b, c);
}
int n;
cin >> n;
int size_sq = a * a + b * b;
while (n--) {
int r;
cin >> r;
if (4 * r * r > size_sq) {
cout << "OK" << endl;
} else {
cout << "NG" << endl;
}
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c;
while (cin >> a >> b >> c, a + b + c) {
if (a > b) {
swap(a, b);
}
if (b > c) {
swap(b, c);
}
int n;
cin >> n;
int size_sq = a * a + b * b;
while (n--) {
int r;
cin >> r;
if (4 * r * r > size_sq) {
cout << "OK" << endl;
} else {
cout << "NA" << endl;
}
}
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 143
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
double m[3];
void solve() {}
int main() {
while (cin >> m[0] >> m[1] >> m[2], m[0] || m[1] || m[2]) {
sort(m, m + 2);
double d = sqrt(m[0] * m[0] + m[1] * m[1]);
int n;
cin >> n;
while (n--) {
double r;
cin >> r;
cout << (d < (r * 2.) ? "OK" : "NA") << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
double m[3];
void solve() {}
int main() {
while (cin >> m[0] >> m[1] >> m[2], m[0] || m[1] || m[2]) {
sort(m, m + 3);
double d = sqrt(m[0] * m[0] + m[1] * m[1]);
int n;
cin >> n;
while (n--) {
double r;
cin >> r;
cout << (d < (r * 2.) ? "OK" : "NA") << endl;
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 145
| 2
|
#include <stdio.h>
int main() {
int a, b, c, p, i;
while (scanf("%d %d %d", &a, &b, &c), a | b | c) {
int m;
if (a >= b && a >= c)
m = b * b + c * c;
if (b >= a && b >= c)
m = a * a + c * c;
if (c >= a && c >= b)
m = a * a + b * b;
scanf("%d", &p);
for (i = 0; i < p; i++) {
scanf("%d", &a);
if (a * a * 4 > m)
puts("OK");
else
puts("NO");
}
}
return 0;
}
|
#include <stdio.h>
int main() {
int a, b, c, p, i;
while (scanf("%d %d %d", &a, &b, &c), a | b | c) {
int m;
if (a >= b && a >= c)
m = b * b + c * c;
if (b >= a && b >= c)
m = a * a + c * c;
if (c >= a && c >= b)
m = a * a + b * b;
scanf("%d", &p);
for (i = 0; i < p; i++) {
scanf("%d", &a);
if (a * a * 4 > m)
puts("OK");
else
puts("NA");
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 171
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
int size[3];
while (cin >> size[0] >> size[1] >> size[2]) {
if (size[0] == 0 && size[1] == 0 && size[2] == 0) {
break;
}
std::sort(size, size + 3);
// 直方体の最小面の対角線
double diagonal = sqrt(pow(size[0], 2) + pow(size[1], 2));
int num_entries, r;
cin >> num_entries;
for (int i = 0; i < num_entries; i++) {
cin >> r;
cout << (r * 2 >= diagonal ? "OK" : "NA") << endl;
}
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
int size[3];
while (cin >> size[0] >> size[1] >> size[2]) {
if (size[0] == 0 && size[1] == 0 && size[2] == 0) {
break;
}
std::sort(size, size + 3);
// 直方体の最小面の対角線
double diagonal = sqrt(pow(size[0], 2) + pow(size[1], 2));
int num_entries, r;
cin >> num_entries;
for (int i = 0; i < num_entries; i++) {
cin >> r;
cout << (r * 2 > diagonal ? "OK" : "NA") << endl;
}
}
}
|
[["-", 31, 16, 12, 23, 0, 41, 15, 16, 17, 20], ["+", 31, 16, 12, 23, 0, 41, 15, 16, 17, 47]]
| 1
| 158
| 2
|
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
int x, y, z, n, r, a, b, c;
while (1) {
scanf("%d %d %d", &x, &y, &z);
if (!x && !y && !z)
break;
scanf("%d", &n);
if (x > y && x > z) {
a = y;
b = z;
} else if (y > z) {
a = z;
b = x;
} else {
a = x;
b = y;
}
c = ceil(sqrt((a * a + b * b) * 0.25));
for (int i = 0; i < n; i++) {
scanf("%d", &r);
if (r < c) {
printf("NA\n");
} else {
printf("OK\n");
}
}
}
return 0;
}
|
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
int x, y, z, n, r, a, b, c;
while (1) {
scanf("%d %d %d", &x, &y, &z);
if (!x && !y && !z)
break;
scanf("%d", &n);
if (x > y && x > z) {
a = y;
b = z;
} else if (y > z) {
a = z;
b = x;
} else {
a = x;
b = y;
}
c = floor(sqrt((a * a + b * b) * 0.25)) + 1;
for (int i = 0; i < n; i++) {
scanf("%d", &r);
if (r < c) {
printf("NA\n");
} else {
printf("OK\n");
}
}
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
| 1
| 200
| 4
|
#include <bits/stdc++.h>
using namespace std;
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();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
#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())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
const double EPS = 1e-10;
const double PI = acos(-1.0);
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
int c[3], n;
while (cin >> c[0] >> c[1] >> c[2], c[0] + c[1] + c[2]) {
sort(c, c + 2);
double size = sqrt(c[0] * c[0] + c[1] * c[1]);
cin >> n;
REP(i, n) {
int r;
cin >> r;
if (2 * r > size)
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
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();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
#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())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
const double EPS = 1e-10;
const double PI = acos(-1.0);
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
int c[3], n;
while (cin >> c[0] >> c[1] >> c[2], c[0] + c[1] + c[2]) {
sort(c, c + 3);
int size = sqrt(c[0] * c[0] + c[1] * c[1]);
cin >> n;
REP(i, n) {
int r;
cin >> r;
if (2 * r > size)
cout << "OK" << endl;
else
cout << "NA" << endl;
}
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40]]
| 1
| 379
| 4
|
include Math
while gets
l, w, h = $_.chomp.split.map(&:to_i)
break if [l,w,h].all?(&:zero?)
cheese_size = [l,w,h].combination(2).map{ |x,y| sqrt(x**2 + y**2) }.min
p cheese_size
n = gets.to_i
cheese_ok = Array.new(n,0)
n.times do |i|
r = gets.to_i
entrance_limit = 2*r
cheese_ok[i] = (cheese_size < entrance_limit ? "OK" : "NA")
end
puts cheese_ok
end
|
include Math
while gets
l, w, h = $_.chomp.split.map(&:to_i)
break if [l,w,h].all?(&:zero?)
cheese_size = [l,w,h].combination(2).map{ |x,y| sqrt(x**2 + y**2) }.min
n = gets.to_i
cheese_ok = Array.new(n,0)
n.times do |i|
r = gets.to_i
entrance_limit = 2*r
cheese_ok[i] = (cheese_size < entrance_limit ? "OK" : "NA")
end
puts cheese_ok
end
|
[["-", 0, 493, 0, 89, 8, 170, 0, 652, 735, 22], ["-", 0, 89, 8, 170, 0, 652, 3, 4, 0, 22]]
| 4
| 127
| 2
|
while True:
solid = sorted(map(int, input().split()))
print(solid)
if solid.count(0) == 3: break
n = eval(input())
s = (solid[0]**2+solid[1]**2)/4
for i in range(n):
r = eval(input())
if r*r > s:
print('OK')
else:
print('NA')
|
while True:
solid = sorted(map(int, input().split()))
if solid.count(0) == 3: break
n = eval(input())
s = (solid[0]**2+solid[1]**2)/4
for i in range(n):
r = eval(input())
if r*r > s:
print('OK')
else:
print('NA')
|
[["-", 0, 52, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 99
| 4
|
while True:
d, w, h = [int(x) for x in input().split()]
minrad = min(d*d+w*w,w*w+h*h,h*h+d*d)
if minrad == 0:
break
n = int(input())
for i in range(n):
r = int(input())
if 2*r*r > minrad:
print('OK')
else:
print('NA')
|
while True:
d, w, h = [int(x) for x in input().split()]
minrad = min(d*d+w*w,w*w+h*h,h*h+d*d)
if minrad == 0:
break
n = int(input())
for i in range(n):
r = int(input())
if 4*r*r > minrad:
print('OK')
else:
print('NA')
|
[["-", 0, 57, 15, 666, 0, 657, 31, 657, 31, 612], ["+", 0, 57, 15, 666, 0, 657, 31, 657, 31, 612]]
| 5
| 106
| 2
|
import math
while True:
d,w,h = map(int,input().split())
if d == 0:
break
n = int(input())
dist = [math.sqrt(d**2+w**2), math.sqrt(d**2+h**2), math.sqrt(w**2+h**2)]
leng = min(dist)
for i in range(n):
if int(input())-leng > 0:
print('OK')
else:
print('NA')
|
import math
while True:
d,w,h = map(int,input().split())
if d == 0:
break
n = int(input())
dist = [math.sqrt(d**2+w**2), math.sqrt(d**2+h**2), math.sqrt(w**2+h**2)]
leng = min(dist)
for i in range(n):
if 2*int(input())-leng > 0:
print('OK')
else:
print('NA')
|
[["+", 0, 57, 15, 666, 0, 657, 31, 657, 31, 612], ["+", 0, 57, 15, 666, 0, 657, 31, 657, 17, 48]]
| 5
| 119
| 2
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
while (1) {
int n, count = 0;
long before[13], after[13], c[13];
scanf(" %d", &n);
if (n == 0)
break;
for (int i = 0; i < n; ++i)
scanf(" %ld", &before[i]);
// loop
while (1) {
for (int i = 0; i <= 120; ++i)
c[i] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (before[i] == before[j])
c[i]++;
}
}
for (int i = 0; i < n; ++i)
after[i] = c[i];
bool flag = true;
for (int i = 0; i < n; ++i) {
if (before[i] != after[i]) {
flag = false;
break;
}
}
if (flag)
break;
/*
for(int i=0; i<n; ++i){
printf("%ld", after[i]);
if(i<n-1) printf(" ");
}
printf("\n");
*/
count++;
for (int i = 0; i < n; ++i)
before[i] = after[i];
}
printf("%d\n", count);
for (int i = 0; i < n; ++i) {
printf("%ld", after[i]);
if (i < n - 1)
printf(" ");
}
printf("\n");
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
while (1) {
int n, count = 0;
long before[13], after[13], c[13];
scanf(" %d", &n);
if (n == 0)
break;
for (int i = 0; i < n; ++i)
scanf(" %ld", &before[i]);
// loop
while (1) {
for (int i = 0; i <= 12; ++i)
c[i] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (before[i] == before[j])
c[i]++;
}
}
for (int i = 0; i < n; ++i)
after[i] = c[i];
bool flag = true;
for (int i = 0; i < n; ++i) {
if (before[i] != after[i]) {
flag = false;
break;
}
}
if (flag)
break;
/*
for(int i=0; i<n; ++i){
printf("%ld", after[i]);
if(i<n-1) printf(" ");
}
printf("\n");
*/
count++;
for (int i = 0; i < n; ++i)
before[i] = after[i];
}
printf("%d\n", count);
for (int i = 0; i < n; ++i) {
printf("%ld", after[i]);
if (i < n - 1)
printf(" ");
}
printf("\n");
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 328
| 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 all(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;
int main() {
int n;
string s;
while (cin >> n) {
if (n == 0)
break;
lint ct = 0;
int s[13] = {};
rep(i, 0, n) { cin >> s[i]; }
int ans[13] = {};
for (ct = 0;; ct++) {
rep(i, 0, 13) { ans[i] = 0; }
int d[13] = {};
rep(i, 0, n) { d[s[i]]++; }
rep(i, 0, n) { ans[i] = d[s[i]]; }
int c = 0;
rep(i, 0, n) {
if (ans[i] == s[i])
c++;
}
if (c == n)
break;
rep(i, 0, n) { s[i] = ans[i]; }
}
o(ct);
rep(i, 0, n) {
if (i == 0)
cout << ans[i];
else
cout << " " << ans[i];
}
cout << endl;
}
}
|
#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 all(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;
int main() {
int n;
while (cin >> n) {
if (n == 0)
break;
lint ct = 0;
int s[13] = {};
rep(i, 0, n) { cin >> s[i]; }
int ans[13] = {};
for (ct = 0;; ct++) {
rep(i, 0, 13) { ans[i] = 0; }
int d[10000] = {};
rep(i, 0, n) { d[s[i]]++; }
rep(i, 0, n) { ans[i] = d[s[i]]; }
int c = 0;
rep(i, 0, n) {
if (ans[i] == s[i])
c++;
}
if (c == n)
break;
rep(i, 0, n) { s[i] = ans[i]; }
}
o(ct);
rep(i, 0, n) {
if (i == 0)
cout << ans[i];
else
cout << " " << ans[i];
}
cout << endl;
}
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13]]
| 1
| 366
| 5
|
#include <iostream>
using namespace std;
bool OperationFA(int *an, int n) {
bool ret = true;
int *cn = new int[n];
for (int i = 0; i < n; i++) {
int mode = 0;
for (int j = 0; j < n; j++) {
if (an[j] == an[i])
mode++;
}
cn[i] = mode;
}
for (int i = 0; i < n; i++) {
if (an[i] != cn[i])
ret = false;
an[i] = cn[i];
}
delete[] cn;
return ret;
}
int main(void) {
while (true) {
int n;
int cnt = 0;
int *an;
cin >> n;
if (n == 0)
break;
an = new int[n];
for (int i = 0; i < n; i++) {
cin >> an[i];
}
while (true) {
if (OperationFA(an, n))
break;
cnt++;
}
cout << cnt << '\n';
cout << an[0];
for (int i = 0; i < n; i++) {
cout << ' ' << an[i];
}
cout << '\n';
delete[] an;
}
return 0;
}
|
#include <iostream>
using namespace std;
bool OperationFA(int *an, int n) {
bool ret = true;
int *cn = new int[n];
for (int i = 0; i < n; i++) {
int mode = 0;
for (int j = 0; j < n; j++) {
if (an[j] == an[i])
mode++;
}
cn[i] = mode;
}
for (int i = 0; i < n; i++) {
if (an[i] != cn[i])
ret = false;
an[i] = cn[i];
}
delete[] cn;
return ret;
}
int main(void) {
while (true) {
int n;
int cnt = 0;
int *an;
cin >> n;
if (n == 0)
break;
an = new int[n];
for (int i = 0; i < n; i++) {
cin >> an[i];
}
while (true) {
if (OperationFA(an, n))
break;
cnt++;
}
cout << cnt << '\n';
cout << an[0];
for (int i = 1; i < n; i++) {
cout << ' ' << an[i];
}
cout << '\n';
delete[] an;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 286
| 2
|
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (!n)
break;
int a[n], b[n];
int count = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
while (true) {
for (int i = 0; i < n; i++) {
int c = 0;
for (int j = 0; j < n; j++)
if (a[j] == a[i])
c++;
b[i] = c;
}
bool bb = true;
for (int i = 0; i < n; i++) {
if (a[i] != b[i])
bb = false;
a[i] = b[i];
}
if (bb)
break;
count++;
}
cout << count << endl;
cout << a[0];
for (int i = 1; i < n - 1; i++)
cout << " " << a[i];
cout << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (!n)
break;
int a[n], b[n];
int count = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
while (true) {
for (int i = 0; i < n; i++) {
int c = 0;
for (int j = 0; j < n; j++)
if (a[j] == a[i])
c++;
b[i] = c;
}
bool bb = true;
for (int i = 0; i < n; i++) {
if (a[i] != b[i])
bb = false;
a[i] = b[i];
}
if (bb)
break;
count++;
}
cout << count << endl;
cout << a[0];
for (int i = 1; i < n; i++)
cout << " " << a[i];
cout << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 233
| 2
|
#include <algorithm>
#include <iostream>
using namespace std;
bool check(int a[12], int b[12], int n) {
bool f = true;
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
f = false;
break;
}
}
return f;
}
int main() {
int n;
while (cin >> n && n) {
int a[12], b[13], c[12], t = 0, s;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
fill(c, c + n, -1);
while (1) {
fill(b, b + 13, 0);
for (int i = 0; i < n; i++) {
b[a[i]]++;
}
s = 1;
for (int i = 1; i <= n; i++) {
s = max(b[s], b[i]);
}
if (check(a, c, n)) {
break;
}
for (int i = 0; i < n; i++) {
c[i] = a[i];
a[i] = b[a[i]];
}
t++;
}
cout << (t - 1) << endl;
cout << a[0];
for (int i = 1; i < n; i++) {
cout << " " << a[i];
}
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
bool check(int a[12], int b[12], int n) {
bool f = true;
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
f = false;
break;
}
}
return f;
}
int main() {
int n;
while (cin >> n && n) {
int a[12], b[10000], c[12], t = 0, s;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
fill(c, c + n, -1);
while (1) {
fill(b, b + 10000, 0);
for (int i = 0; i < n; i++) {
b[a[i]]++;
}
s = 1;
for (int i = 1; i <= n; i++) {
s = max(b[s], b[i]);
}
if (check(a, c, n)) {
break;
}
for (int i = 0; i < n; i++) {
c[i] = a[i];
a[i] = b[a[i]];
}
t++;
}
cout << (t - 1) << endl;
cout << a[0];
for (int i = 1; i < n; i++) {
cout << " " << a[i];
}
cout << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 332
| 4
|
#include <iostream>
using namespace std;
int main() {
int n, s[12], o[12];
while (cin >> n) {
if (!n)
break;
int step = 0;
for (int i = 0; i < n; ++i)
cin >> s[i];
for (int f = 1; f; ++step) {
for (int i = 0; i < n; ++i)
o[i] = s[i];
for (int i = 0, count = 0; i < n; ++i) {
count = 0;
for (int j = 0; j < n; ++j) {
if (o[i] == o[j])
++count;
}
s[i] = count;
}
f = 0;
for (int i = 0; i < n; ++i)
if (s[i] != o[i])
f = 1;
}
cout << step << "\n";
for (int i = 0; i < n; ++i)
cout << s[i] << ((i != n - 1) ? " " : "\n");
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, s[12], o[12];
while (cin >> n) {
if (!n)
break;
int step = -1;
for (int i = 0; i < n; ++i)
cin >> s[i];
for (int f = 1; f; ++step) {
for (int i = 0; i < n; ++i)
o[i] = s[i];
for (int i = 0, count = 0; i < n; ++i) {
count = 0;
for (int j = 0; j < n; ++j) {
if (o[i] == o[j])
++count;
}
s[i] = count;
}
f = 0;
for (int i = 0; i < n; ++i)
if (s[i] != o[i])
f = 1;
}
cout << step << "\n";
for (int i = 0; i < n; ++i)
cout << s[i] << ((i != n - 1) ? " " : "\n");
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 250
| 2
|
def operation_of_foa(input_seq, times)
operated_seq = Array.new
count_seq = Hash.new
input_seq.each do |n|
if count_seq.has_key?(n)
count_seq[n] += 1
else
count_seq[n] = 1
end
end
input_seq.each do |n|
operated_seq << count_seq[n]
end
if operated_seq == input_seq
return [operated_seq, times]
else
operation_of_foa(operated_seq, times+1)
end
end
def print_seq(seq_times)
puts seq_times.last
seq_times.first.each.with_index { |x,i| print (i.zero? ? x : " #{x}") }
puts ""
end
while gets
n = $_.to_i
break if n == 0
input_seq = gets.chomp.split.map(&:to_i)
print_seq(operation_of_foa(input_seq, 1))
end
|
def operation_of_foa(input_seq, times)
operated_seq = Array.new
count_seq = Hash.new
input_seq.each do |n|
if count_seq.has_key?(n)
count_seq[n] += 1
else
count_seq[n] = 1
end
end
input_seq.each do |n|
operated_seq << count_seq[n]
end
if operated_seq == input_seq
return [operated_seq, times-1]
else
operation_of_foa(operated_seq, times+1)
end
end
def print_seq(seq_times)
puts seq_times.last
seq_times.first.each.with_index { |x,i| print (i.zero? ? x : " #{x}") }
puts ""
end
while gets
n = $_.to_i
break if n == 0
input_seq = gets.chomp.split.map(&:to_i)
print_seq(operation_of_foa(input_seq, 1))
end
|
[["+", 0, 38, 0, 4, 0, 516, 0, 738, 17, 33], ["+", 0, 38, 0, 4, 0, 516, 0, 738, 12, 612]]
| 4
| 158
| 2
|
import java.lang.*;
import java.math.*;
import java.util.*;
public class Main {
Scanner sc = new Scanner(System.in);
enum ope {
add,
sub,
mul,
div;
}
LinkedList<String> tokenize(String str) {
String token = "";
LinkedList<String> ret = new LinkedList<String>();
String sp = "+-*/()=";
for (char c : str.toCharArray()) {
if (Character.isDigit(c)) {
token += c;
} else {
if (sp.indexOf(c) != -1) {
if (token.length() != 0)
ret.addLast(token);
ret.addLast(Character.toString(c));
token = "";
}
}
}
return ret;
}
class evTree {
ope o;
String s;
evTree left = null;
evTree right = null;
int val = 0;
int getVal() {
if (left == null && right == null) {
return val;
}
if (o == ope.add) {
// System.out.println(left.s + " add " + right.s);
return left.getVal() + right.getVal();
}
if (o == ope.sub) {
// System.out.println(left.s + " sub " + right.s);
return left.getVal() - right.getVal();
}
if (o == ope.mul) {
// System.out.println(left.s + " mul " + right.s);
return left.getVal() * right.getVal();
}
// if (o == ope.div) {
// System.out.println(left.s + " div " + right.s);
return left.getVal() / right.getVal();
// }
}
boolean evTrimable(LinkedList<String> t) {
if (t.getLast().equals("="))
return true;
if (t.getFirst().equals("(") && t.getLast().equals(")")) {
int depth = 0;
int count = 0;
for (String token : t) {
if (token.equals("(")) {
depth++;
}
if (token.equals(")")) {
depth--;
}
if (depth == 0) {
count++;
}
}
return count == 1;
}
return false;
}
void evTrim(LinkedList<String> t) {
if (t.getLast().equals("=")) {
t.removeLast();
return;
}
t.removeFirst();
t.removeLast();
return;
}
String tts(LinkedList<String> t) {
String ret = "";
for (String s : t) {
ret += s;
}
return ret;
}
evTree(LinkedList<String> t) {
s = tts(t);
if (t.size() == 1) {
this.val = Integer.valueOf(t.get(0));
return;
}
if (t.size() == 0) {
this.val = 0;
return;
}
for (; evTrimable(t);)
evTrim(t);
if (t.size() == 1) {
this.val = Integer.valueOf(t.get(0));
return;
}
if (t.size() == 0) {
this.val = 0;
return;
}
int[] p = new int[t.size()];
int depth = 1;
int min = 100;
for (int i = 0; i < t.size(); i++) {
String token = t.get(i);
if (Character.isDigit(token.toCharArray()[0]))
continue;
if (token.equals("(")) {
depth += 2;
}
if (token.equals(")")) {
depth -= 2;
}
if (token.equals("+") || token.equals("-")) {
p[i] = depth;
}
if (token.equals("*") || token.equals("/")) {
p[i] = depth + 1;
}
}
int z = 0;
for (int i = 0; i < t.size(); i++) {
if (p[i] == 0)
continue;
if (p[i] < min) {
min = p[i];
z = i;
}
}
String token = t.get(z);
if (token.equals("+")) {
this.o = ope.add;
}
if (token.equals("-")) {
this.o = ope.sub;
}
if (token.equals("*")) {
this.o = ope.mul;
}
if (token.equals("/")) {
this.o = ope.div;
}
LinkedList<String> tl = new LinkedList<String>(t.subList(0, z));
this.left = new evTree(tl);
LinkedList<String> tr = new LinkedList<String>(t.subList(z + 1,
t.size()));
this.right = new evTree(tr);
}
}
void run() {
int n = Integer.valueOf(sc.nextLine());
for (; n-- > 0;) {
LinkedList<String> token = tokenize(sc.nextLine());
/*
* for (String t : token) { System.out.println(t); }
*/
System.out.println(new evTree(token).getVal());
}
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
}
|
import java.lang.*;
import java.math.*;
import java.util.*;
public class Main {
Scanner sc = new Scanner(System.in);
enum ope {
add,
sub,
mul,
div;
}
LinkedList<String> tokenize(String str) {
String token = "";
LinkedList<String> ret = new LinkedList<String>();
String sp = "+-*/()=";
for (char c : str.toCharArray()) {
if (Character.isDigit(c)) {
token += c;
} else {
if (sp.indexOf(c) != -1) {
if (token.length() != 0)
ret.addLast(token);
ret.addLast(Character.toString(c));
token = "";
}
}
}
return ret;
}
class evTree {
ope o;
String s;
evTree left = null;
evTree right = null;
int val = 0;
int getVal() {
if (left == null && right == null) {
return val;
}
if (o == ope.add) {
// System.out.println(left.s + " add " + right.s);
return left.getVal() + right.getVal();
}
if (o == ope.sub) {
// System.out.println(left.s + " sub " + right.s);
return left.getVal() - right.getVal();
}
if (o == ope.mul) {
// System.out.println(left.s + " mul " + right.s);
return left.getVal() * right.getVal();
}
// if (o == ope.div) {
// System.out.println(left.s + " div " + right.s);
return left.getVal() / right.getVal();
// }
}
boolean evTrimable(LinkedList<String> t) {
if (t.getLast().equals("="))
return true;
if (t.getFirst().equals("(") && t.getLast().equals(")")) {
int depth = 0;
int count = 0;
for (String token : t) {
if (token.equals("(")) {
depth++;
}
if (token.equals(")")) {
depth--;
}
if (depth == 0) {
count++;
}
}
return count == 1;
}
return false;
}
void evTrim(LinkedList<String> t) {
if (t.getLast().equals("=")) {
t.removeLast();
return;
}
t.removeFirst();
t.removeLast();
return;
}
String tts(LinkedList<String> t) {
String ret = "";
for (String s : t) {
ret += s;
}
return ret;
}
evTree(LinkedList<String> t) {
s = tts(t);
if (t.size() == 1) {
this.val = Integer.valueOf(t.get(0));
return;
}
if (t.size() == 0) {
this.val = 0;
return;
}
for (; evTrimable(t);)
evTrim(t);
if (t.size() == 1) {
this.val = Integer.valueOf(t.get(0));
return;
}
if (t.size() == 0) {
this.val = 0;
return;
}
int[] p = new int[t.size()];
int depth = 1;
int min = 100;
for (int i = 0; i < t.size(); i++) {
String token = t.get(i);
if (Character.isDigit(token.toCharArray()[0]))
continue;
if (token.equals("(")) {
depth += 2;
}
if (token.equals(")")) {
depth -= 2;
}
if (token.equals("+") || token.equals("-")) {
p[i] = depth;
}
if (token.equals("*") || token.equals("/")) {
p[i] = depth + 1;
}
}
int z = 0;
for (int i = 0; i < t.size(); i++) {
if (p[i] == 0)
continue;
if (p[i] <= min) {
min = p[i];
z = i;
}
}
String token = t.get(z);
if (token.equals("+")) {
this.o = ope.add;
}
if (token.equals("-")) {
this.o = ope.sub;
}
if (token.equals("*")) {
this.o = ope.mul;
}
if (token.equals("/")) {
this.o = ope.div;
}
LinkedList<String> tl = new LinkedList<String>(t.subList(0, z));
this.left = new evTree(tl);
LinkedList<String> tr = new LinkedList<String>(t.subList(z + 1,
t.size()));
this.right = new evTree(tr);
}
}
void run() {
int n = Integer.valueOf(sc.nextLine());
for (; n-- > 0;) {
LinkedList<String> token = tokenize(sc.nextLine());
/*
* for (String t : token) { System.out.println(t); }
*/
System.out.println(new evTree(token).getVal());
}
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 19]]
| 3
| 1,125
| 2
|
#include <stdio.h>
char s[110];
int p = 0;
double f(double a, int b, double c) {
if (b == 2)
return a + c;
if (b == 3)
return a - c;
if (b == 4)
return a * c;
return a / c;
}
int kobun() {
int i, r = 0, o[3], or [] = {0, 0, 1, 1, 2, 2};
int n[3], a;
char c[] = {")=+-*/"};
while (1) {
for (a = 0; '0' <= s[p] && s[p] <= '9'; p++)
a = a * 10 + s[p] - '0';
if (s[p] == '(') {
p++;
a = kobun();
}
for (i = 0; s[p] - c[i]; i++)
;
for (; r && o[r - 1] >= or [i]; r--)
a = f(n[r - 1], o[r - 1], a);
n[r] = a;
o[r++] = or [i];
p++;
if (or [i] == 0)
return n[0];
}
return 0;
}
int main() {
int n;
for (scanf("%d", &n); n--; p = 0) {
scanf("%s", s);
printf("%d\n", kobun());
}
return 0;
}
|
#include <stdio.h>
char s[110];
int p = 0;
double f(double a, int b, double c) {
if (b == 2)
return a + c;
if (b == 3)
return a - c;
if (b == 4)
return a * c;
return a / c;
}
int kobun() {
int i, r = 0, o[3], or [] = {0, 0, 1, 1, 2, 2};
int n[3], a;
char c[] = {")=+-*/"};
while (1) {
for (a = 0; '0' <= s[p] && s[p] <= '9'; p++)
a = a * 10 + s[p] - '0';
if (s[p] == '(') {
p++;
a = kobun();
}
for (i = 0; s[p] - c[i]; i++)
;
for (; r && or [o[r - 1]] >= or [i]; r--)
a = f(n[r - 1], o[r - 1], a);
n[r] = a;
o[r++] = i;
p++;
if (or [i] == 0)
return n[0];
}
return 0;
}
int main() {
int n;
for (scanf("%d", &n); n--; p = 0) {
scanf("%s", s);
printf("%d\n", kobun());
}
return 0;
}
|
[["+", 0, 7, 15, 16, 12, 16, 31, 69, 28, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 69, 0, 70], ["+", 15, 16, 12, 16, 31, 69, 71, 69, 0, 73], ["-", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22], ["-", 8, 9, 0, 1, 0, 11, 12, 69, 0, 70], ["-", 8, 9, 0, 1, 0, 11, 12, 69, 0, 73]]
| 0
| 344
| 6
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CALC \
{ \
if (sign == 0) \
term = term * x; \
else \
term = term / x; \
}
int num;
char str[101];
int smartCalc() {
int sum = 0, term = 1, sign = 0, x = 0;
while (1) {
switch (str[num]) {
case '*':
CALC;
sign = 0;
x = 0;
break;
case '/':
CALC;
sign = 1;
x = 0;
break;
case '+':
CALC;
sum += term;
term = 1;
sign = 0;
x = 0;
break;
case '-':
CALC;
sum += term;
term = -1;
sign = 0;
x = 0;
break;
case '(':
num += 1;
x = smartCalc();
break;
case ')':
break;
case '=':
CALC;
sum += term;
return sum;
break;
default:
x = x * 10 + str[num] - '0';
}
num += 1;
}
}
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", str);
num = 0;
printf("%d\n", smartCalc());
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CALC \
{ \
if (sign == 0) \
term = term * x; \
else \
term = term / x; \
}
int num;
char str[101];
int smartCalc() {
int sum = 0, term = 1, sign = 0, x = 0;
while (1) {
switch (str[num]) {
case '*':
CALC;
sign = 0;
x = 0;
break;
case '/':
CALC;
sign = 1;
x = 0;
break;
case '+':
CALC;
sum += term;
term = 1;
sign = 0;
x = 0;
break;
case '-':
CALC;
sum += term;
term = -1;
sign = 0;
x = 0;
break;
case '(':
num += 1;
x = smartCalc();
break;
case ')':
case '=':
CALC;
sum += term;
return sum;
break;
default:
x = x * 10 + str[num] - '0';
}
num += 1;
}
}
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", str);
num = 0;
printf("%d\n", smartCalc());
}
return 0;
}
|
[["-", 0, 99, 8, 9, 0, 100, 0, 93, 0, 94], ["-", 0, 99, 8, 9, 0, 100, 0, 93, 0, 35]]
| 0
| 266
| 2
|
#include <ctype.h>
#include <stdio.h>
#include <strings.h>
char str[101];
int tindex = 0;
int map[255];
int token;
int addminus();
void getToken(void) {
int r = 0;
if (isdigit(str[tindex])) {
while (isdigit(str[tindex])) {
r = r * 10 + (str[tindex++] - '0');
}
token = r;
} else {
token = map[(int)str[tindex++]];
}
}
int terminal() {
int result = 0;
if (token == -5) {
getToken();
result = addminus();
getToken();
} else if (token >= 0) {
result = token;
getToken();
}
return result;
}
int multidiv() {
int result = terminal();
while (token == -3 || token == -4) {
if (token == -3) {
getToken();
result *= terminal();
} else {
getToken();
result /= terminal();
}
}
return result;
}
int addminus() {
int result = multidiv();
while (token == -1 || token == -2) {
if (token == -1) {
getToken();
result += multidiv();
} else {
getToken();
result -= multidiv();
}
}
return result;
}
int main(void) {
int i, n, total;
map['+'] = -1;
map['-'] = -2;
map['*'] = -3;
map['/'] = -4;
map['('] = -5;
map[')'] = -6;
map['='] = -7;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", str);
getToken();
total = addminus();
printf("%d\n", total);
}
return 0;
}
|
#include <ctype.h>
#include <stdio.h>
#include <strings.h>
char str[101];
int tindex = 0;
int map[255];
int token;
int addminus();
void getToken(void) {
int r = 0;
if (isdigit(str[tindex])) {
while (isdigit(str[tindex])) {
r = r * 10 + (str[tindex++] - '0');
}
token = r;
} else {
token = map[(int)str[tindex++]];
}
}
int terminal() {
int result = 0;
if (token == -5) {
getToken();
result = addminus();
getToken();
} else if (token >= 0) {
result = token;
getToken();
}
return result;
}
int multidiv() {
int result = terminal();
while (token == -3 || token == -4) {
if (token == -3) {
getToken();
result *= terminal();
} else {
getToken();
result /= terminal();
}
}
return result;
}
int addminus() {
int result = multidiv();
while (token == -1 || token == -2) {
if (token == -1) {
getToken();
result += multidiv();
} else {
getToken();
result -= multidiv();
}
}
return result;
}
int main(void) {
int i, n, total;
map['+'] = -1;
map['-'] = -2;
map['*'] = -3;
map['/'] = -4;
map['('] = -5;
map[')'] = -6;
map['='] = -7;
scanf("%d", &n);
for (i = 0; i < n; i++) {
tindex = 0;
scanf("%s", str);
getToken();
total = addminus();
printf("%d\n", total);
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
| 0
| 411
| 4
|
#include <stdio.h>
#include <string.h>
#define def_func(name) int name(int f, int l)
#define gen_func(name, next, aop1, op1, aop2, op2) \
def_func(name) { \
int i; \
for (i = l; i >= f; i--) { \
if (expr[i] == ')') \
i = find_open(f, i - 1) - 1; \
if (expr[i] == aop1) \
return (name(f, i - 1) op1 next(i + 1, l)); \
if (expr[i] == aop1) \
return (name(f, i - 1) op1 next(i + 1, l)); \
} \
return (next(f, l)); \
}
char expr[128];
def_func(eval);
def_func(term);
def_func(factor);
def_func(find_open);
int main(void) {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf(" %s", expr);
printf("%d\n", eval(0, strlen(expr) - 2));
}
return (0);
}
gen_func(eval, term, '+', +, '-', -) gen_func(term, factor, '*', *, '/', /)
def_func(factor) {
if (expr[f] == '(')
return (eval(f + 1, l - 1));
return (atoi(expr + f));
}
def_func(find_open) {
int i;
int close = 0;
for (i = l; i >= f; i--) {
if (expr[i] == ')')
close++;
if (expr[i] == '(') {
if (close == 0)
break;
close--;
}
}
return (i);
}
|
#include <stdio.h>
#include <string.h>
#define def_func(name) int name(int f, int l)
#define gen_func(name, next, aop1, op1, aop2, op2) \
def_func(name) { \
int i; \
for (i = l; i >= f; i--) { \
if (expr[i] == ')') \
i = find_open(f, i - 1) - 1; \
if (expr[i] == aop1) \
return (name(f, i - 1) op1 next(i + 1, l)); \
if (expr[i] == aop2) \
return (name(f, i - 1) op2 next(i + 1, l)); \
} \
return (next(f, l)); \
}
char expr[128];
def_func(eval);
def_func(term);
def_func(factor);
def_func(find_open);
int main(void) {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf(" %s", expr);
printf("%d\n", eval(0, strlen(expr) - 2));
}
return (0);
}
gen_func(eval, term, '+', +, '-', -) gen_func(term, factor, '*', *, '/', /)
def_func(factor) {
if (expr[f] == '(')
return (eval(f + 1, l - 1));
return (atoi(expr + f));
}
def_func(find_open) {
int i;
int close = 0;
for (i = l; i >= f; i--) {
if (expr[i] == ')')
close++;
if (expr[i] == '(') {
if (close == 0)
break;
close--;
}
}
return (i);
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59]]
| 0
| 273
| 2
|
#include <cctype>
#include <iostream>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef string::const_iterator State;
int ctoi(const char &c) { return c - '0'; }
int expression(State &);
int term(State &);
int factor(State &);
int number(State &);
int expression(State &itr) {
int ret = term(itr);
while (true) {
if (*itr == '+') {
itr++;
ret = ret + term(itr);
} else if (*itr == '-') {
itr++;
ret = ret - term(itr);
} else {
break;
}
}
return ret;
}
int term(State &itr) {
int ret = number(itr);
while (true) {
if (*itr == '*') {
itr++;
ret = ret * factor(itr);
} else if (*itr == '/') {
itr++;
ret = ret / factor(itr);
} else {
break;
}
}
return ret;
}
int factor(State &itr) {
int ret;
if (*itr == '(') {
itr++;
ret = expression(itr);
itr++;
} else {
ret = number(itr);
}
return ret;
}
int number(State &itr) {
int ret = 0;
while (isdigit(*itr)) {
ret *= 10;
ret += ctoi(*itr);
itr++;
}
return ret;
}
int main() {
int n;
cin >> n;
cin.ignore();
REP(i, n) {
string str;
getline(cin, str);
State begin = str.begin();
int ans = expression(begin);
cout << ans << endl;
}
return 0;
}
|
#include <cctype>
#include <iostream>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef string::const_iterator State;
int ctoi(const char &c) { return c - '0'; }
int expression(State &);
int term(State &);
int factor(State &);
int number(State &);
int expression(State &itr) {
int ret = term(itr);
while (true) {
if (*itr == '+') {
itr++;
ret = ret + term(itr);
} else if (*itr == '-') {
itr++;
ret = ret - term(itr);
} else {
break;
}
}
return ret;
}
int term(State &itr) {
int ret = factor(itr);
while (true) {
if (*itr == '*') {
itr++;
ret = ret * factor(itr);
} else if (*itr == '/') {
itr++;
ret = ret / factor(itr);
} else {
break;
}
}
return ret;
}
int factor(State &itr) {
int ret;
if (*itr == '(') {
itr++;
ret = expression(itr);
itr++;
} else {
ret = number(itr);
}
return ret;
}
int number(State &itr) {
int ret = 0;
while (isdigit(*itr)) {
ret *= 10;
ret += ctoi(*itr);
itr++;
}
return ret;
}
int main() {
int n;
cin >> n;
cin.ignore();
REP(i, n) {
string str;
getline(cin, str);
State begin = str.begin();
int ans = expression(begin);
cout << ans << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22]]
| 1
| 379
| 2
|
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int64 exp(string &, int32 &);
int64 term(string &, int32 &);
int64 fact(string &, int32 &);
int64 number(string &, int32 &);
int64 exp(string &s, int32 &p) {
int64 ret = term(s, p);
while (p < s.size()) {
if (s[p] == '+') {
p++;
ret += term(s, p);
} else if (s[p] == '-') {
p++;
ret -= term(s, p);
} else {
break;
}
}
return ret;
}
int64 term(string &s, int32 &p) {
int64 ret = number(s, p);
while (p < s.size()) {
if (s[p] == '*') {
p++;
ret *= fact(s, p);
} else if (s[p] == '/') {
p++;
ret /= fact(s, p);
} else {
break;
}
}
return ret;
}
int64 fact(string &s, int32 &p) {
int64 ret = 0;
if (s[p] == '(') {
p++;
ret = exp(s, p);
p++;
} else {
ret = number(s, p);
}
return ret;
}
int64 number(string &s, int32 &p) {
int64 ret = 0;
while (isdigit(s[p])) {
ret = ret * 10 + s[p] - '0';
p++;
}
return ret;
}
int main(void) {
int32 N;
cin >> N;
REP(i, N) {
string s;
int32 p = 0;
cin >> s;
cout << exp(s, p) << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
int64 exp(string &, int32 &);
int64 term(string &, int32 &);
int64 fact(string &, int32 &);
int64 number(string &, int32 &);
int64 exp(string &s, int32 &p) {
int64 ret = term(s, p);
while (p < s.size()) {
if (s[p] == '+') {
p++;
ret += term(s, p);
} else if (s[p] == '-') {
p++;
ret -= term(s, p);
} else {
break;
}
}
return ret;
}
int64 term(string &s, int32 &p) {
int64 ret = fact(s, p);
while (p < s.size()) {
if (s[p] == '*') {
p++;
ret *= fact(s, p);
} else if (s[p] == '/') {
p++;
ret /= fact(s, p);
} else {
break;
}
}
return ret;
}
int64 fact(string &s, int32 &p) {
int64 ret = 0;
if (s[p] == '(') {
p++;
ret = exp(s, p);
p++;
} else {
ret = number(s, p);
}
return ret;
}
int64 number(string &s, int32 &p) {
int64 ret = 0;
while (isdigit(s[p])) {
ret = ret * 10 + s[p] - '0';
p++;
}
return ret;
}
int main(void) {
int32 N;
cin >> N;
REP(i, N) {
string s;
int32 p = 0;
cin >> s;
cout << exp(s, p) << endl;
}
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22]]
| 1
| 535
| 2
|
// 構文解析の練習
// https://gist.github.com/draftcode/1357281
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef string::const_iterator State;
class ParseError {};
int number(State &);
int term(State &);
int expression(State &);
int factor(State &);
int number(State &begin) {
int ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += *begin - '0';
begin++;
}
return ret;
}
int term(State &begin) {
int ret = number(begin);
while (1) {
if (*begin == '*') {
begin++;
ret *= factor(begin);
} else if (*begin == '/') {
begin++;
ret /= factor(begin);
} else {
break;
}
}
return ret;
}
int expression(State &begin) {
int ret = term(begin);
while (1) {
if (*begin == '+') {
begin++;
ret += term(begin);
} else if (*begin == '-') {
begin++;
ret -= term(begin);
} else {
break;
}
}
return ret;
}
int factor(State &begin) {
int ret = 0;
if (*begin == '(') {
begin++; // ( を飛ばす
ret = expression(begin);
begin++; // ) を飛ばす
} else {
ret = number(begin);
}
return ret;
}
int main() {
int N;
cin >> N;
cin.ignore();
rep(i, N) {
string s;
getline(cin, s);
State begin = s.begin();
int ans = expression(begin);
cout << ans << endl;
}
return 0;
}
|
// 構文解析の練習
// https://gist.github.com/draftcode/1357281
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef string::const_iterator State;
class ParseError {};
int number(State &);
int term(State &);
int expression(State &);
int factor(State &);
int number(State &begin) {
int ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += *begin - '0';
begin++;
}
return ret;
}
int term(State &begin) {
int ret = factor(begin);
while (1) {
if (*begin == '*') {
begin++;
ret *= factor(begin);
} else if (*begin == '/') {
begin++;
ret /= factor(begin);
} else {
break;
}
}
return ret;
}
int expression(State &begin) {
int ret = term(begin);
while (1) {
if (*begin == '+') {
begin++;
ret += term(begin);
} else if (*begin == '-') {
begin++;
ret -= term(begin);
} else {
break;
}
}
return ret;
}
int factor(State &begin) {
int ret = 0;
if (*begin == '(') {
begin++; // ( を飛ばす
ret = expression(begin);
begin++; // ) を飛ばす
} else {
ret = number(begin);
}
return ret;
}
int main() {
int N;
cin >> N;
cin.ignore();
rep(i, N) {
string s;
getline(cin, s);
State begin = s.begin();
int ans = expression(begin);
cout << ans << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22]]
| 1
| 366
| 2
|
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
typedef string::const_iterator State;
class ParseError {};
/*
<??????????????????> ::= <??????????????????> (+ or -) <??????????????????>
(+ or -) ...
<??????????????????> ::= <??°> (* or /) <??°> (* or /) ...
<??°> ::= ...
*/
int expression(State &begin);
int term(State &begin);
int number(State &begin);
int factor(State &begin);
int factor(State &begin) {
if (*begin == '(') {
begin++;
int ret = expression(begin);
begin++;
} else {
return number(begin);
}
}
int main(void) {
int N;
cin >> N;
cin.ignore();
for (int i = 0; i < N; i++) {
string s;
getline(cin, s);
State begin = s.begin();
int ans = expression(begin);
cout << ans << endl;
}
return 0;
}
int expression(State &begin) {
int ret = term(begin);
for (;;) {
if (*begin == '+') {
begin++;
ret += term(begin);
} else if (*begin == '-') {
begin++;
ret -= term(begin);
} else {
break;
}
}
return ret;
}
int term(State &begin) {
int ret = number(begin);
for (;;) {
if (*begin == '*') {
begin++;
ret *= factor(begin);
} else if (*begin == '/') {
begin++;
ret /= factor(begin);
} else {
break;
}
}
return ret;
}
int number(State &begin) {
int ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += *begin - '0';
begin++;
}
return ret;
}
|
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
typedef string::const_iterator State;
class ParseError {};
/*
<??????????????????> ::= <??????????????????> (+ or -) <??????????????????>
(+ or -) ...
<??????????????????> ::= <??°> (* or /) <??°> (* or /) ...
<??°> ::= ...
*/
int expression(State &begin);
int term(State &begin);
int number(State &begin);
int factor(State &begin);
int factor(State &begin) {
if (*begin == '(') {
begin++;
int ret = expression(begin);
begin++;
return ret;
} else {
return number(begin);
}
}
int main(void) {
int N;
cin >> N;
cin.ignore();
for (int i = 0; i < N; i++) {
string s;
getline(cin, s);
State begin = s.begin();
int ans = expression(begin);
cout << ans << endl;
}
return 0;
}
int expression(State &begin) {
int ret = term(begin);
for (;;) {
if (*begin == '+') {
begin++;
ret += term(begin);
} else if (*begin == '-') {
begin++;
ret -= term(begin);
} else {
break;
}
}
return ret;
}
int term(State &begin) {
int ret = factor(begin);
for (;;) {
if (*begin == '*') {
begin++;
ret *= factor(begin);
} else if (*begin == '/') {
begin++;
ret /= factor(begin);
} else {
break;
}
}
return ret;
}
int number(State &begin) {
int ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += *begin - '0';
begin++;
}
return ret;
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 22], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 35], ["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22]]
| 1
| 362
| 5
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FFOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, b) FOR(i, 0, b)
#define RREP(i, b) FFOR(i, 1, b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(), c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut, ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut, pr> ppr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
const int SIZE = 1e+5 + 10;
const ut INF = 1 << 30;
const ld eps = 1e-6;
const LL mod = 1e+9 + 7;
typedef string::const_iterator SC;
int factor(SC &);
// ??°????????????
int number(SC &begin) {
int res = 0;
while (isdigit(*begin)) {
res *= 10;
res += *begin - '0';
begin++;
}
return res;
}
// ??????
int term(SC &begin) {
int res = factor(begin);
while (1) {
if (*begin == '*') {
begin++;
res *= factor(begin);
} else if (*begin == '/') {
begin++;
res /= factor(begin);
} else {
break;
}
}
return res;
}
// ????????????
int expression(SC &begin) {
int res = term(begin);
while (1) {
if (*begin == '+') {
begin++;
res += term(begin);
} else if (*begin == '-') {
begin++;
res -= term(begin);
} else {
break;
}
}
return res;
}
// ??¬??§?????°????????????
int factor(SC &begin) {
if (*begin == '(') {
begin++;
int res = expression(begin);
begin++;
} else {
return number(begin);
}
}
int main() {
int n;
cin >> n;
string s;
REP(i, n) {
cin >> s;
SC begin = s.begin();
cout << expression(begin) << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FFOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, b) FOR(i, 0, b)
#define RREP(i, b) FFOR(i, 1, b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(), c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut, ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut, pr> ppr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
const int SIZE = 1e+5 + 10;
const ut INF = 1 << 30;
const ld eps = 1e-6;
const LL mod = 1e+9 + 7;
typedef string::const_iterator SC;
int factor(SC &);
// ??°????????????
int number(SC &begin) {
int res = 0;
while (isdigit(*begin)) {
res *= 10;
res += *begin - '0';
begin++;
}
return res;
}
// ??????
int term(SC &begin) {
int res = factor(begin);
while (1) {
if (*begin == '*') {
begin++;
res *= factor(begin);
} else if (*begin == '/') {
begin++;
res /= factor(begin);
} else {
break;
}
}
return res;
}
// ????????????
int expression(SC &begin) {
int res = term(begin);
while (1) {
if (*begin == '+') {
begin++;
res += term(begin);
} else if (*begin == '-') {
begin++;
res -= term(begin);
} else {
break;
}
}
return res;
}
// ??¬??§?????°????????????
int factor(SC &begin) {
if (*begin == '(') {
begin++;
int res = expression(begin);
begin++;
return res;
} else {
return number(begin);
}
}
int main() {
int n;
cin >> n;
string s;
REP(i, n) {
cin >> s;
SC begin = s.begin();
cout << expression(begin) << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 22], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 35]]
| 1
| 469
| 3
|
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
typedef string::const_iterator State;
class ParseError {};
int expression(State &);
int term(State &);
int number(State &);
int factor(State &);
int main(void) {
int N;
cin >> N;
cin.ignore();
for (int i = 0; i < N; i++) {
string s;
getline(cin, s);
State begin = s.begin();
int ans = expression(begin);
cout << ans << endl;
}
return 0;
}
int expression(State &begin) {
int ret = term(begin);
while (1) {
if (*begin == '+') {
begin++;
ret += term(begin);
} else if (*begin == '-') {
begin++;
ret -= term(begin);
} else {
break;
}
}
return ret;
}
int term(State &begin) {
int ret = number(begin);
while (1) {
if (*begin == '*') {
begin++;
ret *= factor(begin);
} else if (*begin == '/') {
begin++;
ret /= factor(begin);
} else {
break;
}
}
return ret;
}
int number(State &begin) {
int ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += *begin - '0';
begin++;
}
return ret;
}
int factor(State &begin) {
if (*begin == '(') {
begin++;
int ret = expression(begin);
begin++;
return ret;
} else {
return number(begin);
}
}
|
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
typedef string::const_iterator State;
class ParseError {};
int expression(State &);
int term(State &);
int number(State &);
int factor(State &);
int main(void) {
int N;
cin >> N;
cin.ignore();
for (int i = 0; i < N; i++) {
string s;
getline(cin, s);
State begin = s.begin();
int ans = expression(begin);
cout << ans << endl;
}
return 0;
}
int expression(State &begin) {
int ret = term(begin);
while (1) {
if (*begin == '+') {
begin++;
ret += term(begin);
} else if (*begin == '-') {
begin++;
ret -= term(begin);
} else {
break;
}
}
return ret;
}
int term(State &begin) {
int ret = factor(begin);
while (1) {
if (*begin == '*') {
begin++;
ret *= factor(begin);
} else if (*begin == '/') {
begin++;
ret /= factor(begin);
} else {
break;
}
}
return ret;
}
int number(State &begin) {
int ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += *begin - '0';
begin++;
}
return ret;
}
int factor(State &begin) {
if (*begin == '(') {
begin++;
int ret = expression(begin);
begin++;
return ret;
} else {
return number(begin);
}
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22]]
| 1
| 358
| 2
|
#include "bits/stdc++.h"
#include <unordered_map>
#pragma warning(disable : 4996)
using namespace std;
string st;
int a;
int plmi();
int num() {
int n = 0;
while (1) {
if (isdigit(st[a])) {
n *= 10;
n += st[a] - '0';
a++;
} else {
return n;
}
}
}
int siki() {
int n;
if (st[a] == '(') {
a++;
n = plmi();
a++;
} else {
n = num();
}
return n;
}
int evdi() {
int n = num();
while (1) {
if (st[a] == '*') {
a++;
n *= siki();
} else if (st[a] == '/') {
a++;
n /= siki();
} else {
break;
}
}
return n;
}
int plmi() {
int n = evdi();
while (1) {
if (st[a] == '+') {
a++;
n += evdi();
} else if (st[a] == '-') {
a++;
n -= evdi();
} else {
break;
}
}
return n;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> st;
a = 0;
int ans = plmi();
cout << ans << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#pragma warning(disable : 4996)
using namespace std;
string st;
int a;
int plmi();
int num() {
int n = 0;
while (1) {
if (isdigit(st[a])) {
n *= 10;
n += st[a] - '0';
a++;
} else {
return n;
}
}
}
int siki() {
int n;
if (st[a] == '(') {
a++;
n = plmi();
a++;
} else {
n = num();
}
return n;
}
int evdi() {
int n = siki();
while (1) {
if (st[a] == '*') {
a++;
n *= siki();
} else if (st[a] == '/') {
a++;
n /= siki();
} else {
break;
}
}
return n;
}
int plmi() {
int n = evdi();
while (1) {
if (st[a] == '+') {
a++;
n += evdi();
} else if (st[a] == '-') {
a++;
n -= evdi();
} else {
break;
}
}
return n;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> st;
a = 0;
int ans = plmi();
cout << ans << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22]]
| 1
| 319
| 2
|
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int exp(string &s, int &i);
int term(string &s, int &i);
int factor(string &s, int &i);
int number(string &s, int &i);
int exp(string &s, int &i) {
int val = term(s, i);
while (s[i] == '+' || s[i] == '-') {
char op = s[i];
i++;
int val2 = term(s, i);
if (op == '+')
val += val2;
else
val -= val2;
}
return val;
}
int term(string &s, int &i) {
int val = factor(s, i);
while (s[i] == '*' || s[i] == '/') {
char op = s[i];
i++;
int val2 = factor(s, i);
if (op == '*')
val *= val2;
else
val /= val2;
}
return val;
}
int factor(string &s, int &i) {
if (isdigit(s[i]))
return number(s, i);
i++;
int val = exp(s, i);
i++;
return val;
}
int number(string &s, int &i) {
int n = s[i] = '0';
i++;
while (isdigit(s[i])) {
n = n * 10 + (s[i] - '0');
i++;
}
return n;
}
int main() {
int n;
cin >> n;
for (int j = 0; j < n; j++) {
string s;
cin >> s;
int i = 0;
cout << exp(s, i) << endl;
}
}
|
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int exp(string &s, int &i);
int term(string &s, int &i);
int factor(string &s, int &i);
int number(string &s, int &i);
int exp(string &s, int &i) {
int val = term(s, i);
while (s[i] == '+' || s[i] == '-') {
char op = s[i];
i++;
int val2 = term(s, i);
if (op == '+')
val += val2;
else
val -= val2;
}
return val;
}
int term(string &s, int &i) {
int val = factor(s, i);
while (s[i] == '*' || s[i] == '/') {
char op = s[i];
i++;
int val2 = factor(s, i);
if (op == '*')
val *= val2;
else
val /= val2;
}
return val;
}
int factor(string &s, int &i) {
if (isdigit(s[i]))
return number(s, i);
i++;
int val = exp(s, i);
i++;
return val;
}
int number(string &s, int &i) {
int n = s[i] - '0';
i++;
while (isdigit(s[i])) {
n = n * 10 + (s[i] - '0');
i++;
}
return n;
}
int main() {
int n;
cin >> n;
for (int j = 0; j < n; j++) {
string s;
cin >> s;
int i = 0;
cout << exp(s, i) << endl;
}
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 11, 17, 32], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 33]]
| 1
| 397
| 2
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n;
string S;
int cur;
int digit() {
assert(isdigit(S[cur]));
int n = S[cur] - '0';
cur++;
return n;
}
int number() {
int n = digit();
while (cur < S.size() && isdigit(S[cur])) {
n = n * 10 + digit();
}
return n;
}
int expression();
int factor() {
if (S[cur] != '(')
return number();
cur++;
int n = expression();
cur++;
return n;
}
int term() {
int sum = number();
while (cur < S.size() && (S[cur] == '*' || S[cur] == '/')) {
char op = S[cur];
cur++;
int b = number();
if (op == '*')
sum *= b;
else
sum /= b;
}
return sum;
}
int expression() {
int sum = term();
while (cur < S.size() && (S[cur] == '+' || S[cur] == '-')) {
char op = S[cur];
cur++;
int b = term();
if (op == '+')
sum += b;
else
sum -= b;
}
return sum;
}
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
cur = 0;
cin >> S;
S.resize(S.size() - 1);
cout << expression() << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n;
string S;
int cur;
int digit() {
assert(isdigit(S[cur]));
int n = S[cur] - '0';
cur++;
return n;
}
int number() {
int n = digit();
while (cur < S.size() && isdigit(S[cur])) {
n = n * 10 + digit();
}
return n;
}
int expression();
int factor() {
if (S[cur] != '(')
return number();
cur++;
int n = expression();
cur++;
return n;
}
int term() {
int sum = factor();
while (cur < S.size() && (S[cur] == '*' || S[cur] == '/')) {
char op = S[cur];
cur++;
int b = factor();
if (op == '*')
sum *= b;
else
sum /= b;
}
return sum;
}
int expression() {
int sum = term();
while (cur < S.size() && (S[cur] == '+' || S[cur] == '-')) {
char op = S[cur];
cur++;
int b = term();
if (op == '+')
sum += b;
else
sum -= b;
}
return sum;
}
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
cur = 0;
cin >> S;
S.resize(S.size() - 1);
cout << expression() << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22]]
| 1
| 390
| 4
|
def get_input():
while True:
try:
yield ''.join(input())
except EOFError:
break
dict = {"A":"00000",\
"B":"00001",\
"C":"00010",\
"D":"00011",\
"E":"00100",\
"F":"00101",\
"G":"00110", \
"H":"00111", \
"I":"01000", \
"J":"01001", \
"K":"01010", \
"L":"01011", \
"M":"01100", \
"N":"01101", \
"O":"01110", \
"P":"01111", \
"Q":"10000", \
"R":"10001", \
"S":"10010", \
"T":"10011", \
"U":"10100", \
"V":"10101", \
"W":"10110", \
"X":"10111", \
"Y":"11000", \
"Z":"11001", \
" ":"11010", \
".":"11011", \
",":"11100", \
"-":"11101", \
"'":"11110", \
"?":"11111"}
dict2 = {"101":" ",\
"000000":"'",\
"000011":",", \
"10010001":"-", \
"010001":".",\
"000001":"?",\
"100101":"A",\
"10011010":"B",\
"0101":"C",\
"0001":"D",\
"110":"E",\
"01001":"F",\
"10011011":"G",\
"010000":"H",\
"0111":"I",\
"10011000":"J",\
"0110":"K",\
"00100":"L",\
"10011001":"M",\
"10011110":"N",\
"00101":"O",\
"111":"P",\
"10011111":"Q",\
"1000":"R",\
"00110":"S",\
"00111":"T",\
"10011100":"U",\
"10011101":"V",\
"000010":"W",\
"10010010":"X",\
"10010011":"Y",\
"10010000":"Z"}
N = list(get_input())
for l in range(len(N)):
S1 = N[l]
S2 = ""
for i in range(len(S1)):
S2 = S2 + dict[S1[i]]
S3 = ""
while S2 != "":
flag = False
for i in range(3, len(S2)):
s = S2[0:i]
if s in dict2:
S3 = S3 + dict2[s]
S2 = S2[i:]
flag = True
break
if flag == False:
break
print(S3)
|
def get_input():
while True:
try:
yield ''.join(input())
except EOFError:
break
dict = {"A":"00000",\
"B":"00001",\
"C":"00010",\
"D":"00011",\
"E":"00100",\
"F":"00101",\
"G":"00110", \
"H":"00111", \
"I":"01000", \
"J":"01001", \
"K":"01010", \
"L":"01011", \
"M":"01100", \
"N":"01101", \
"O":"01110", \
"P":"01111", \
"Q":"10000", \
"R":"10001", \
"S":"10010", \
"T":"10011", \
"U":"10100", \
"V":"10101", \
"W":"10110", \
"X":"10111", \
"Y":"11000", \
"Z":"11001", \
" ":"11010", \
".":"11011", \
",":"11100", \
"-":"11101", \
"'":"11110", \
"?":"11111"}
dict2 = {"101":" ",\
"000000":"'",\
"000011":",", \
"10010001":"-", \
"010001":".",\
"000001":"?",\
"100101":"A",\
"10011010":"B",\
"0101":"C",\
"0001":"D",\
"110":"E",\
"01001":"F",\
"10011011":"G",\
"010000":"H",\
"0111":"I",\
"10011000":"J",\
"0110":"K",\
"00100":"L",\
"10011001":"M",\
"10011110":"N",\
"00101":"O",\
"111":"P",\
"10011111":"Q",\
"1000":"R",\
"00110":"S",\
"00111":"T",\
"10011100":"U",\
"10011101":"V",\
"000010":"W",\
"10010010":"X",\
"10010011":"Y",\
"10010000":"Z"}
N = list(get_input())
for l in range(len(N)):
S1 = N[l]
S2 = ""
for i in range(len(S1)):
S2 = S2 + dict[S1[i]]
S3 = ""
while S2 != "":
flag = False
for i in range(3, len(S2)+1):
s = S2[0:i]
if s in dict2:
S3 = S3 + dict2[s]
S2 = S2[i:]
flag = True
break
if flag == False:
break
print(S3)
|
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 723
| 2
|
#include <stdio.h>
int main(void) {
int n;
int customer[10000];
int i;
int flag;
int buf;
int time[10000];
int total;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
for (i = 0; i < n; i++) {
scanf("%d", &customer[i]);
}
/*昇順にソート*/
flag == 1;
while (flag == 1) {
flag = 0;
for (i = 0; i < n - 1; i++) {
if (customer[i] > customer[i + 1]) {
buf = customer[i];
customer[i] = customer[i + 1];
customer[i + 1] = buf;
flag = 1;
}
}
}
for (i = 0; i < n; i++) {
time[i] = 0;
}
total = 0;
for (i = 0; i < n; i++) {
if (i != 0) {
time[i] = time[i - 1] + customer[i - 1];
total += time[i];
}
/*printf("%d\n", time[i]);*/
}
printf("%d\n", total);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int n;
int customer[10000];
int i;
int flag;
int buf;
int time[10000];
long long total;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
for (i = 0; i < n; i++) {
scanf("%d", &customer[i]);
}
/*昇順にソート*/
flag = 1;
while (flag == 1) {
flag = 0;
for (i = 0; i < n - 1; i++) {
if (customer[i] > customer[i + 1]) {
buf = customer[i];
customer[i] = customer[i + 1];
customer[i + 1] = buf;
flag = 1;
}
}
}
for (i = 0; i < n; i++) {
time[i] = 0;
}
total = 0;
for (i = 0; i < n; i++) {
if (i != 0) {
time[i] = time[i - 1] + customer[i - 1];
total += time[i];
}
/*printf("%d %d\n", customer[i], time[i]);*/
}
printf("%lld\n", total);
}
return (0);
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 60], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 263
| 7
|
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
int n;
while (scanf("%d", &n) * n != 0) {
int waitt[10000] = {0};
int i, j;
long sum = 0;
for (i = 0; i < n; i++)
scanf("%d", waitt + i);
sort(waitt, waitt + n);
for (i = 0; i < n; i++) {
for (j = 0; j <= i; j++) {
sum += waitt[j];
}
}
printf("%ld\n", sum);
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
int n;
while (scanf("%d", &n) * n != 0) {
int waitt[10000] = {0};
int i, j;
long sum = 0;
for (i = 0; i < n; i++)
scanf("%d", waitt + i);
sort(waitt, waitt + n);
for (i = 0; i < n - 1; i++) {
for (j = 0; j <= i; j++) {
sum += waitt[j];
}
}
printf("%ld\n", sum);
}
return 0;
}
|
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 138
| 2
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
int emp[10000];
long long time;
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> emp[i];
}
sort(emp, emp + n - 1);
time = 0;
for (int i = 0; i < n; i++) {
time += emp[i] * (n - 1 - i);
}
cout << time << endl;
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
int emp[10000];
long long time;
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> emp[i];
}
sort(emp, emp + n);
time = 0;
for (int i = 0; i < n; i++) {
time += emp[i] * (n - 1 - i);
}
cout << time << endl;
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 120
| 2
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
vector<int> ts;
for (int i = 0; i < n; i++) {
cin >> ts[i];
}
sort(ts.begin(), ts.end());
long long sum = 0, ans = 0;
for (int i = 0; i < n; i++) {
ans += sum;
sum += ts[i];
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
vector<int> ts(n);
for (int i = 0; i < n; i++) {
cin >> ts[i];
}
sort(ts.begin(), ts.end());
long long sum = 0, ans = 0;
for (int i = 0; i < n; i++) {
ans += sum;
sum += ts[i];
}
cout << ans << endl;
}
}
|
[["+", 8, 9, 0, 43, 49, 53, 54, 55, 0, 24], ["+", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 8, 9, 0, 43, 49, 53, 54, 55, 0, 25]]
| 1
| 116
| 3
|
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;
int main() {
int i, n;
while (cin >> n, n) {
int m[10000] = {'\0'};
for (i = 0; i < n; i++) {
cin >> m[i];
}
long long ans = 0;
int j = 0, sum = 0;
sort(m, m + n - 1);
for (int j = 0; j < i - 1; j++) {
sum += m[j];
ans += sum;
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;
int main() {
int i, n;
while (cin >> n, n) {
int m[10000] = {'\0'};
for (i = 0; i < n; i++) {
cin >> m[i];
}
long long ans = 0;
int j = 0, sum = 0;
sort(m, m + n);
for (int j = 0; j < i - 1; j++) {
sum += m[j];
ans += sum;
}
cout << ans << endl;
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 160
| 2
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n, time[1000];
long long ans;
while (cin >> n) {
if (n == 0)
break;
int wait = 0;
for (int i = 0; i < n; i++)
cin >> time[i];
sort(time, time + n);
for (int i = 0; i < n; i++) {
ans += wait;
wait += time[i];
}
cout << ans << endl;
ans = 0;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n, time[10000];
long long ans = 0;
while (cin >> n) {
if (n == 0)
break;
int wait = 0;
for (int i = 0; i < n; i++)
cin >> time[i];
sort(time, time + n);
for (int i = 0; i < n; i++) {
ans += wait;
wait += time[i];
}
cout << ans << endl;
ans = 0;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 119
| 4
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int P, Q;
while (cin >> P >> Q) {
map<int, int> latte;
int m = 0, l = 0, r = 0;
vector<int> ans;
latte[P % Q] = 0;
m = P % Q;
while (m) {
int nm = m * 10 % Q;
ans.push_back(m * 10 / Q);
if (latte.find(nm) != latte.end()) {
l = latte[nm];
r = ans.size();
break;
}
latte[nm] = ans.size() - 1;
m = nm;
}
for (int i = 0; i < ans.size(); i++)
printf("%d", ans[i]);
puts("");
if (r != 0) {
for (int i = 0; i < ans.size(); i++) {
if (l <= i)
printf("^");
else
printf(" ");
}
puts("");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int P, Q;
while (cin >> P >> Q) {
map<int, int> latte;
int m = 0, l = 0, r = 0;
vector<int> ans;
latte[P % Q] = 0;
m = P % Q;
while (m) {
int nm = m * 10 % Q;
ans.push_back(m * 10 / Q);
if (latte.find(nm) != latte.end()) {
l = latte[nm];
r = ans.size();
break;
}
latte[nm] = ans.size();
m = nm;
}
for (int i = 0; i < ans.size(); i++)
printf("%d", ans[i]);
puts("");
if (r != 0) {
for (int i = 0; i < ans.size(); i++) {
if (l <= i)
printf("^");
else
printf(" ");
}
puts("");
}
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
| 1
| 240
| 2
|
#include <algorithm>
#include <iostream>
#include <vector>
typedef std::pair<int, int> P;
int main() {
int a = 0, b = 0;
while (std::cin >> a >> b, !std::cin.eof()) {
std::vector<P> v;
while (1) {
a *= 10;
if (std::find(v.begin(), v.end(), P(a % b, a / b)) != v.end())
break;
v.push_back(P(a % b, a / b));
a %= b;
}
int first = std::find(v.begin(), v.end(), P(a % b, a / b)) - v.begin();
for (int i = 0; i < v.size(); i++) {
std::cout << v[i].second;
}
std::cout << std::endl;
if (a % b == 0)
continue;
for (int i = 0; i < v.size(); i++) {
if (i >= first)
std::cout << "^";
else
std::cout << " ";
}
std::cout << std::endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <vector>
typedef std::pair<int, int> P;
int main() {
int a = 0, b = 0;
while (std::cin >> a >> b, !std::cin.eof()) {
std::vector<P> v;
while (a % b) {
a *= 10;
if (std::find(v.begin(), v.end(), P(a % b, a / b)) != v.end())
break;
v.push_back(P(a % b, a / b));
a %= b;
}
int first = std::find(v.begin(), v.end(), P(a % b, a / b)) - v.begin();
for (int i = 0; i < v.size(); i++) {
std::cout << v[i].second;
}
std::cout << std::endl;
if (a % b == 0)
continue;
for (int i = 0; i < v.size(); i++) {
if (i >= first)
std::cout << "^";
else
std::cout << " ";
}
std::cout << std::endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 52, 15, 339, 51, 13], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 109], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
| 1
| 266
| 4
|
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()
const int MAX = 85;
int main() {
int p, q;
while (cin >> p >> q) {
int quot[MAX] = {}, resi[MAX] = {};
int b = -1, e = -1, iscycle = 1;
for (int i = 0; p != 0; i++) {
quot[i] = p / q;
resi[i] = p % q;
p = (p % q) * 10;
rep(j, i) if (resi[i] == resi[j]) {
b = j;
e = i;
break;
}
if (b != -1)
break;
if (resi[i] == 0) {
e = i + 1;
iscycle = 0;
break;
}
}
if (iscycle) {
REP(e) cout << quot[i + 1];
cout << endl;
REP(e) {
if (i < b)
cout << " ";
else
cout << "^";
}
cout << endl;
} else {
REP(e) cout << quot[i + 1];
cout << endl;
}
}
return 0;
}
|
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()
const int MAX = 185;
int main() {
int p, q;
while (cin >> p >> q) {
int quot[MAX] = {}, resi[MAX] = {};
int b = -1, e = -1, iscycle = 1;
for (int i = 0; p != 0; i++) {
quot[i] = p / q;
resi[i] = p % q;
p = (p % q) * 10;
rep(j, i) if (resi[i] == resi[j]) {
b = j;
e = i;
break;
}
if (b != -1)
break;
if (resi[i] == 0) {
e = i;
iscycle = 0;
break;
}
}
if (iscycle) {
REP(e) cout << quot[i + 1];
cout << endl;
REP(e) {
if (i < b)
cout << " ";
else
cout << "^";
}
cout << endl;
} else {
REP(e) cout << quot[i + 1];
cout << endl;
}
}
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
| 1
| 274
| 4
|
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdio.h>
using namespace std;
int main() {
int p, q;
while (cin >> p >> q) {
bool amari[1000000] = {0};
string s;
bool flag = false;
queue<int> qu;
while (1) {
p = p % q * 10;
if (p == 0)
break;
// cout<<p<<endl;
if (amari[p / 10]) {
flag = true;
break;
}
amari[p / 10] = true;
qu.push(p / 10);
s += p / q + '0';
}
cout << s << endl;
flag = true;
while (!qu.empty()) {
if (qu.front() == p / 10)
flag = false;
if (flag)
cout << " ";
else
cout << "^";
qu.pop();
}
cout << endl;
}
}
|
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdio.h>
using namespace std;
int main() {
int p, q;
while (cin >> p >> q) {
bool amari[1000000] = {0};
string s;
bool flag = false;
queue<int> qu;
while (1) {
p = p % q * 10;
if (p == 0)
break;
// cout<<p<<endl;
if (amari[p / 10]) {
flag = true;
break;
}
amari[p / 10] = true;
qu.push(p / 10);
s += p / q + '0';
}
cout << s << endl;
if (flag) {
flag = true;
while (!qu.empty()) {
if (qu.front() == p / 10)
flag = false;
if (flag)
cout << " ";
else
cout << "^";
qu.pop();
}
cout << endl;
}
}
}
|
[["+", 8, 9, 0, 52, 8, 9, 0, 57, 0, 121], ["+", 0, 52, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 52, 8, 9, 0, 57, 15, 339, 51, 22], ["+", 0, 52, 8, 9, 0, 57, 15, 339, 0, 25], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 201
| 6
|
while True:
n = int(input())
if n==0:break
wt = [int(input()) for _ in range(n)]
total = wt[0]
s = []
for v in sorted(wt[1:]):
s.append(total)
total += v
print(sum(s))
|
while True:
n = int(input())
if n==0:break
wt = sorted([int(input()) for _ in range(n)])
total = wt[0]
s = []
for v in wt[1:]:
s.append(total)
total += v
print(sum(s))
|
[["+", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25], ["-", 0, 52, 8, 196, 0, 7, 12, 652, 63, 22], ["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 25]]
| 5
| 72
| 6
|
import java.util.HashMap;
import java.util.Scanner;
public class Main {
private Scanner sc;
public static void main(String[] args) { new Main(); }
public Main() {
sc = new Scanner(System.in);
while (sc.hasNextLine() == true) {
String line = sc.nextLine();
String[] nico = line.split(" ");
int p = Integer.parseInt(nico[0]) * 10;
int q = Integer.parseInt(nico[1]);
HashMap<Integer, Integer> pmap = new HashMap<Integer, Integer>();
int index = 0;
String ans = "";
while ((p % q) != 0) {
int div = p / q;
if (pmap.containsKey(p) == true) {
int lim = ans.length();
ans = ans + "\n";
for (int i = 0; i < pmap.get(p); i++) {
ans = ans + " ";
}
for (int i = 0; i < (lim - pmap.get(p)); i++) {
ans = ans + "^";
}
break;
}
pmap.put(p, index);
ans = ans + div;
index++;
p = (p - div * q) * 10;
}
System.out.println(ans);
}
}
}
|
import java.util.HashMap;
import java.util.Scanner;
public class Main {
private Scanner sc;
public static void main(String[] args) { new Main(); }
public Main() {
sc = new Scanner(System.in);
while (sc.hasNextLine() == true) {
String line = sc.nextLine();
String[] nico = line.split(" ");
int p = Integer.parseInt(nico[0]) * 10;
int q = Integer.parseInt(nico[1]);
HashMap<Integer, Integer> pmap = new HashMap<Integer, Integer>();
int index = 0;
String ans = "";
while (p != 0) {
int div = p / q;
if (pmap.containsKey(p) == true) {
int lim = ans.length();
ans = ans + "\n";
for (int i = 0; i < pmap.get(p); i++) {
ans = ans + " ";
}
for (int i = 0; i < (lim - pmap.get(p)); i++) {
ans = ans + "^";
}
break;
}
pmap.put(p, index);
ans = ans + div;
index++;
p = (p - div * q) * 10;
}
System.out.println(ans);
}
}
}
|
[["-", 0, 52, 15, 15, 0, 16, 31, 23, 0, 24], ["-", 15, 15, 0, 16, 31, 23, 0, 16, 17, 109], ["-", 15, 15, 0, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 52, 15, 15, 0, 16, 31, 23, 0, 25]]
| 3
| 300
| 4
|
#include <stdio.h>
int gcd(int a, int b) {
int c;
while ((c = a % b) != 0) {
a = b;
b = c;
}
return b;
}
int main() {
long a1, m1, a2, m2, a3, m3, count, x1, x2, x3, i, ac, bc, cc, lc;
do {
scanf("%ld %ld %ld %ld %ld %ld", &a1, &m1, &a2, &m2, &a3, &m3);
if (!a1 && !m1 && !a2 && !m2 && !a3 && !m3)
break;
for (i = a1, ac = 1; i != 1; i = (a1 * i) % m1, ac++)
;
for (i = a2, bc = 1; i != 1; i = (a2 * i) % m2, bc++)
;
for (i = a3, cc = 1; i != 1; i = (a3 * i) % m3, cc++)
;
lc = ac * bc / gcd(ac, bc);
lc = lc * cc / gcd(lc, cc);
printf("%d\n", lc);
} while (1);
return 0;
}
|
#include <stdio.h>
int gcd(int a, int b) {
int c;
while ((c = a % b) != 0) {
a = b;
b = c;
}
return b;
}
int main() {
long a1, m1, a2, m2, a3, m3, count, x1, x2, x3, i, ac, bc, cc;
long long int lc;
do {
scanf("%ld %ld %ld %ld %ld %ld", &a1, &m1, &a2, &m2, &a3, &m3);
if (!a1 && !m1 && !a2 && !m2 && !a3 && !m3)
break;
for (i = a1, ac = 1; i != 1; i = (a1 * i) % m1, ac++)
;
for (i = a2, bc = 1; i != 1; i = (a2 * i) % m2, bc++)
;
for (i = a3, cc = 1; i != 1; i = (a3 * i) % m3, cc++)
;
lc = ac * bc / gcd(ac, bc);
lc = lc * cc / gcd(lc, cc);
printf("%lld\n", lc);
} while (1);
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 39, 40], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 256
| 7
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.