buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
int n = sc.nextInt();
int[] values = new int[w];
for (int i = 0; i < values.length; i++) {
values[i] = i + 1;
}
for (int i = 0; i < n; i++) {
String str = sc.next();
String[] ab = str.split(",");
int a = Integer.parseInt(ab[0]) - 1;
int b = Integer.parseInt(ab[1]);
int temp = values[a];
values[a] = values[b];
values[b] = temp;
}
for (int i = 0; i < values.length; i++) {
System.out.printf("%d\n", values[i]);
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
int n = sc.nextInt();
int[] values = new int[w];
for (int i = 0; i < values.length; i++) {
values[i] = i + 1;
}
for (int i = 0; i < n; i++) {
String str = sc.next();
String[] ab = str.split(",");
int a = Integer.parseInt(ab[0]) - 1;
int b = Integer.parseInt(ab[1]) - 1;
int temp = values[a];
values[a] = values[b];
values[b] = temp;
}
for (int i = 0; i < values.length; i++) {
System.out.printf("%d\n", values[i]);
}
}
}
|
[["+", 8, 196, 0, 503, 49, 200, 51, 16, 17, 33], ["+", 8, 196, 0, 503, 49, 200, 51, 16, 12, 499]]
| 3
| 218
| 2
|
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);
int num = Integer.parseInt(sc.nextLine());
int[] e = new int[num];
for (int i = 0; i < num; i++) {
e[i] = i + 1;
}
int lim = Integer.parseInt(sc.nextLine());
for (int i = 0; i < lim; i++) {
String[] params = sc.nextLine().split(",");
int l = Integer.parseInt(params[0]);
int r = Integer.parseInt(params[1]);
int tmp = e[l];
e[l] = e[r];
e[r] = tmp;
}
for (int i = 0; i < num; i++) {
System.out.println(e[i]);
}
}
}
|
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);
int num = Integer.parseInt(sc.nextLine());
int[] e = new int[num];
for (int i = 0; i < num; i++) {
e[i] = i + 1;
}
int lim = Integer.parseInt(sc.nextLine());
for (int i = 0; i < lim; i++) {
String[] params = sc.nextLine().split(",");
int l = Integer.parseInt(params[0]) - 1;
int r = Integer.parseInt(params[1]) - 1;
int tmp = e[l];
e[l] = e[r];
e[r] = tmp;
}
for (int i = 0; i < num; i++) {
System.out.println(e[i]);
}
}
}
|
[["+", 8, 196, 0, 503, 49, 200, 51, 16, 17, 33], ["+", 8, 196, 0, 503, 49, 200, 51, 16, 12, 499]]
| 3
| 226
| 4
|
import java.util.*;
public class Main {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int w = scan.nextInt();
int[] dl = new int[w];
for (int i = 0; i < w; i++) {
dl[i] = i + 1;
}
int n = scan.nextInt();
for (int i = 0; i < n; i++) {
String input = scan.nextLine();
String[] nums = input.split("\\,");
int a = Integer.parseInt(nums[0]);
int b = Integer.parseInt(nums[1]);
int work = dl[a - 1];
dl[a - 1] = dl[b - 1];
dl[b - 1] = work;
}
for (int i = 0; i < w; i++) {
System.out.printf("%d\n", dl[i]);
}
}
}
|
import java.util.*;
public class Main {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int w = scan.nextInt();
int[] dl = new int[w];
for (int i = 0; i < w; i++) {
dl[i] = i + 1;
}
int n = scan.nextInt();
for (int i = 0; i < n; i++) {
String input = scan.next();
String[] nums = input.split(",");
int a = Integer.parseInt(nums[0]);
int b = Integer.parseInt(nums[1]);
int work = dl[a - 1];
dl[a - 1] = dl[b - 1];
dl[b - 1] = work;
}
for (int i = 0; i < w; i++) {
System.out.printf("%d\n", dl[i]);
}
}
}
|
[["-", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["-", 49, 200, 51, 492, 3, 4, 0, 5, 0, 44]]
| 3
| 224
| 3
|
import sys
n=10**5
s=[True]*n
s[0]=False
s[1]=False
for x in range(2, int(n**0.5)+1):
if s[x]:
for i in range(x+x,n,x):
s[i]=False
for x in sys.stdin.readlines():
x=int(x)
cnt=0
for i in range(x):
if s[i]:
cnt=cnt+1
print(cnt)
|
import sys
n=10**6
s=[True]*n
s[0]=False
s[1]=False
for x in range(2, int(n**0.5)+1):
if s[x]:
for i in range(x+x,n,x):
s[i]=False
for x in sys.stdin.readlines():
x=int(x)+1
cnt=0
for i in range(x):
if s[i]:
cnt=cnt+1
print(cnt)
|
[["-", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
| 5
| 112
| 4
|
import math
def get_primes(max_number):#return prime list smaller than max_number
if max_number == 2:
return [2]
elif max_number < 3:
return []
numbers=list(range(1, max_number + 2, 2))
nroot=math.floor(max_number ** 0.5)
n=len(numbers)
numbers[0]=0
for i in range(1, n):
x = numbers[i]
if x > nroot:
break
if x and i + x < n:
for j in range(i+x,n+1,x):
numbers[j] = 0
x=[2] + [_f for _f in numbers[1:] if _f]
return x
n=[]
i=0
while (True):
try:
n.append([i,eval(input()), 0])
i+=1
except:
break
n=sorted(n, key=lambda x: x[1])
for i, e in enumerate(get_primes(n[-1][1])):
for j in range(len(n)):
if e<=n[j][1]:
n[j][2]+=1
n=sorted(n, key=lambda x: x[0])
for e in n:
print(e[2])
|
import math
def get_primes(max_number):#return prime list smaller than max_number
if max_number == 2:
return [2]
elif max_number < 3:
return []
numbers=list(range(1, max_number + 2, 2))
nroot=math.floor(max_number ** 0.5)
n=len(numbers)
numbers[0]=0
for i in range(1, n):
x = numbers[i]
if x > nroot:
break
if x and i + x < n:
for j in range(i+x,n,x):
numbers[j] = 0
x=[2] + [_f for _f in numbers[1:] if _f]
return x
n=[]
i=0
while (True):
try:
n.append([i,eval(input()), 0])
i+=1
except:
break
n=sorted(n, key=lambda x: x[1])
for i, e in enumerate(get_primes(n[-1][1])):
for j in range(len(n)):
if e<=n[j][1]:
n[j][2]+=1
n=sorted(n, key=lambda x: x[0])
for e in n:
print(e[2])
|
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 269
| 2
|
from bisect import bisect
def sieve(n):
num = [True]*n
num[0] = num[1] = False
for i in range(2,int(n**0.5)+1):
if num[i]:
for j in range(i**2, n, i):
num[j] = False
return [i for i in range(2,n) if num[i]]
prime = sieve(999999)
while True:
try:
print(bisect(is_prime, eval(input())))
except:
break
|
from bisect import bisect
def sieve(n):
num = [True]*n
num[0] = num[1] = False
for i in range(2,int(n**0.5)+1):
if num[i]:
for j in range(i**2, n, i):
num[j] = False
return [i for i in range(2,n) if num[i]]
prime = sieve(999999)
while True:
try:
print(bisect(prime, eval(input())))
except:
break
|
[["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 22]]
| 5
| 117
| 2
|
<?php
function to_f($e) {
return (int)$e;
}
$n = fgets(STDIN);
for($i=0; $i<(int)$n; $i++) {
$line = fgets(STDIN);
$a = explode(" ", $line);
$a = array_map("to_f", $a);
$a1 = 2*($a[2]-$a[0]);
$a2 = 2*($a[4]-$a[0]);
$b1 = 2*($a[3]-$a[1]);
$b2 = 2*($a[5]-$a[1]);
$c1 = $a[0]*$a[0]-$a[2]*$a[2]+$a[1]*$a[1]-$a[3]*$a[3];
$c2 = $a[0]*$a[0]-$a[4]*$a[4]+$a[1]*$a[1]-$a[5]*$a[5];
$xp = ($b1*$c2-$b2*$c1)/($a1*$b2-$a2*$b1);
$yp = ($c1*$a2-$c2*$a1)/($a1*$b2-$a2*$b1);
$r = sqrt(($xp-$a[0])*($xp-$a[0])+($yp-$a[1])*($yp-$a[1]));
printf("%.3f %.3f %.3f\n", $xp, $yp, $r);
}
|
<?php
function to_d($e) {
return (double)$e;
}
$n = fgets(STDIN);
for($i=0; $i<(double)$n; $i++) {
$line = fgets(STDIN);
$a = explode(" ", $line);
$a = array_map("to_d", $a);
$a1 = 2*($a[2]-$a[0]);
$a2 = 2*($a[4]-$a[0]);
$b1 = 2*($a[3]-$a[1]);
$b2 = 2*($a[5]-$a[1]);
$c1 = $a[0]*$a[0]-$a[2]*$a[2]+$a[1]*$a[1]-$a[3]*$a[3];
$c2 = $a[0]*$a[0]-$a[4]*$a[4]+$a[1]*$a[1]-$a[5]*$a[5];
$xp = ($b1*$c2-$b2*$c1)/($a1*$b2-$a2*$b1);
$yp = ($c1*$a2-$c2*$a1)/($a1*$b2-$a2*$b1);
$r = sqrt(($xp-$a[0])*($xp-$a[0])+($yp-$a[1])*($yp-$a[1]));
printf("%.3f %.3f %.3f\n", $xp, $yp, $r);
}
|
[["-", 36, 36, 36, 36, 0, 493, 0, 14, 141, 141], ["+", 36, 36, 36, 36, 0, 493, 0, 14, 141, 141], ["-", 0, 14, 8, 9, 0, 37, 0, 74, 39, 615], ["+", 0, 14, 8, 9, 0, 37, 0, 74, 39, 615], ["-", 0, 493, 0, 7, 0, 16, 12, 74, 39, 615], ["+", 0, 493, 0, 7, 0, 16, 12, 74, 39, 615], ["-", 12, 613, 3, 3, 0, 28, 0, 609, 0, 610], ["+", 12, 613, 3, 3, 0, 28, 0, 609, 0, 610]]
| 6
| 387
| 8
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
double x3 = sc.nextDouble();
double y3 = sc.nextDouble();
double a = Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0);
double b = Math.pow(x3 - x2, 2.0) + Math.pow(y3 - y2, 2.0);
double c = Math.pow(x1 - x3, 2.0) + Math.pow(y1 - y3, 2.0);
double s =
Math.pow(0.5 * ((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)), 2.0);
double px =
(a * (b + c - a) * x3 + b * (c + a - b) * x1 + c * (a + b - c) * x2) /
(16 * s);
double py =
(a * (b + c - a) * y3 + b * (c + a - b) * y1 + c * (a + b - c) * y2) /
(16 * s);
double r = Math.pow(px - x1, 2.0) + Math.pow(py - y1, 2.0);
System.out.printf("%.3f\n", px);
System.out.printf("%.3f\n", py);
System.out.printf("%.3f\n", Math.sqrt(r));
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
double x3 = sc.nextDouble();
double y3 = sc.nextDouble();
double a = Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0);
double b = Math.pow(x3 - x2, 2.0) + Math.pow(y3 - y2, 2.0);
double c = Math.pow(x1 - x3, 2.0) + Math.pow(y1 - y3, 2.0);
double s =
Math.pow(0.5 * ((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)), 2.0);
double px =
(a * (b + c - a) * x3 + b * (c + a - b) * x1 + c * (a + b - c) * x2) /
(16 * s);
double py =
(a * (b + c - a) * y3 + b * (c + a - b) * y1 + c * (a + b - c) * y2) /
(16 * s);
double r = Math.pow(px - x1, 2.0) + Math.pow(py - y1, 2.0);
System.out.printf("%.3f ", px);
System.out.printf("%.3f ", py);
System.out.printf("%.3f\n", Math.sqrt(r));
}
}
}
|
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
| 3
| 393
| 6
|
import java.util.*;
public class Main {
public static double x1, x2, y1, y2, x3, y3, a, b, c, a1, b1, c1, xp, yp;
static double z(double z1, double z2, double z3, double z4) {
return Math.sqrt(Math.pow(z3 - z1, 2) + Math.pow(z4 - z2, 2));
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
x1 = sc.nextDouble();
y1 = sc.nextDouble();
x2 = sc.nextDouble();
y2 = sc.nextDouble();
x3 = sc.nextDouble();
y3 = sc.nextDouble();
a = 2 * (x2 - x1);
a1 = 2 * (x3 - x1);
b = 2 * (y2 - y1);
b1 = 2 * (y3 - y1);
c = Math.pow(x1, 2) - Math.pow(x2, 2) + Math.pow(y1, 2) -
Math.pow(y2, 2);
c1 = Math.pow(x1, 2) - Math.pow(x3, 2) + Math.pow(y1, 2) -
Math.pow(y3, 2);
xp = (b * c1 - b1 * c) / (a * b1 - a1 * b);
yp = (c * a1 - c1 * a) / (a * b1 - a1 * b);
System.out.printf("%.3f %.3f %3f\n", xp, yp, z(x1, y1, xp, yp));
}
}
}
}
|
import java.util.*;
public class Main {
public static double x1, x2, y1, y2, x3, y3, a, b, c, a1, b1, c1, xp, yp;
static double z(double z1, double z2, double z3, double z4) {
return Math.sqrt(Math.pow(z3 - z1, 2) + Math.pow(z4 - z2, 2));
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
x1 = sc.nextDouble();
y1 = sc.nextDouble();
x2 = sc.nextDouble();
y2 = sc.nextDouble();
x3 = sc.nextDouble();
y3 = sc.nextDouble();
a = 2 * (x2 - x1);
a1 = 2 * (x3 - x1);
b = 2 * (y2 - y1);
b1 = 2 * (y3 - y1);
c = Math.pow(x1, 2) - Math.pow(x2, 2) + Math.pow(y1, 2) -
Math.pow(y2, 2);
c1 = Math.pow(x1, 2) - Math.pow(x3, 2) + Math.pow(y1, 2) -
Math.pow(y3, 2);
xp = (b * c1 - b1 * c) / (a * b1 - a1 * b);
yp = (c * a1 - c1 * a) / (a * b1 - a1 * b);
System.out.printf("%.3f %.3f %.3f\n", xp, yp, z(x1, y1, xp, yp));
}
}
}
}
|
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
| 3
| 382
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
double x3 = sc.nextDouble();
double y3 = sc.nextDouble();
double a = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
double b = Math.sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
double c = Math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
double s = (a + b + c) / 2;
double r = a * b * c / (4 * Math.sqrt(s * (s - a) * (s - b) * (s - c)));
double A1 = 2 * (x2 - x1);
double B1 = 2 * (y2 - y1);
double C1 = (x1 * x1) - (x2 * x2) + (y1 * y1) - (y2 * y2);
double A2 = 2 * (x3 - x1);
double B2 = 2 * (y3 - y1);
double C2 = (x1 * x1) - (x3 * x3) + (y1 * y1) - (y3 * y3);
double X = (B1 * C2 - B2 * C1) / (A1 * B2 - A2 * B1);
double Y = (C1 * A2 - C2 * A1) / (A1 * B2 - A2 * B1);
System.out.printf("%.3f %.3f %.3f/n", X, Y, r);
}
}
public static double sr(double a) {
a = a * 10000;
if (a % 10 >= 5) {
a += 10 - a % 10;
} else {
a -= a % 10;
}
int b = (int)a;
return (b / 10000.0);
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
double x3 = sc.nextDouble();
double y3 = sc.nextDouble();
double a = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
double b = Math.sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
double c = Math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
double s = (a + b + c) / 2;
double r = a * b * c / (4 * Math.sqrt(s * (s - a) * (s - b) * (s - c)));
double A1 = 2 * (x2 - x1);
double B1 = 2 * (y2 - y1);
double C1 = (x1 * x1) - (x2 * x2) + (y1 * y1) - (y2 * y2);
double A2 = 2 * (x3 - x1);
double B2 = 2 * (y3 - y1);
double C2 = (x1 * x1) - (x3 * x3) + (y1 * y1) - (y3 * y3);
double X = (B1 * C2 - B2 * C1) / (A1 * B2 - A2 * B1);
double Y = (C1 * A2 - C2 * A1) / (A1 * B2 - A2 * B1);
System.out.printf("%.3f %.3f %.3f\n", X, Y, r);
}
}
public static double sr(double a) {
a = a * 10000;
if (a % 10 >= 5) {
a += 10 - a % 10;
} else {
a -= a % 10;
}
int b = (int)a;
return (b / 10000.0);
}
}
|
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 44]]
| 3
| 480
| 3
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] argv) throws IOException {
//*
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int count = 1;
count = Integer.parseInt(in.readLine());
while (count-- > 0) {
String s = in.readLine();
if (s == null) {
break;
}
f(s);
}
//*/
}
public static void f(String s) {
String[] temp = s.split(" ");
double[] points = new double[temp.length];
for (int i = 0; i < temp.length; i++) {
points[i] = Double.parseDouble(temp[i]);
}
double a = Math.sqrt(Math.pow(Math.abs(points[0] - points[2]), 2) +
Math.pow(Math.abs(points[1] - points[3]), 2));
double b = Math.sqrt(Math.pow(Math.abs(points[2] - points[4]), 2) +
Math.pow(Math.abs(points[3] - points[5]), 2));
double c = Math.sqrt(Math.pow(Math.abs(points[4] - points[0]), 2) +
Math.pow(Math.abs(points[5] - points[1]), 2));
double R = (a * b * c) / Math.sqrt((a + b + c) * (-a + b + c) *
(a - b + c) * (a + b - c));
double a1 = 2 * (points[2] - points[0]);
double b1 = 2 * (points[3] - points[1]);
double c1 = Math.pow(points[0], 2) - Math.pow(points[2], 2) +
Math.pow(points[1], 2) - Math.pow(points[3], 2);
double a2 = 2 * (points[2] - points[0]);
double b2 = 2 * (points[5] - points[3]);
double c2 = Math.pow(points[0], 2) - Math.pow(points[2], 2) +
Math.pow(points[3], 2) - Math.pow(points[5], 2);
double x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
double y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
System.out.println(String.format(
"%.3f %.3f %.3f", Math.round(x * 1000) / 1000.0,
Math.round(y * 1000) / 1000.0, Math.round(R * 1000) / 1000.0));
}
}
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] argv) throws IOException {
//*
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int count = 1;
count = Integer.parseInt(in.readLine());
while (count-- > 0) {
String s = in.readLine();
if (s == null) {
break;
}
f(s);
}
//*/
}
public static void f(String s) {
String[] temp = s.split(" ");
double[] points = new double[temp.length];
for (int i = 0; i < temp.length; i++) {
points[i] = Double.parseDouble(temp[i]);
}
double a = Math.sqrt(Math.pow(Math.abs(points[0] - points[2]), 2) +
Math.pow(Math.abs(points[1] - points[3]), 2));
double b = Math.sqrt(Math.pow(Math.abs(points[2] - points[4]), 2) +
Math.pow(Math.abs(points[3] - points[5]), 2));
double c = Math.sqrt(Math.pow(Math.abs(points[4] - points[0]), 2) +
Math.pow(Math.abs(points[5] - points[1]), 2));
double R = (a * b * c) / Math.sqrt((a + b + c) * (-a + b + c) *
(a - b + c) * (a + b - c));
double a1 = 2 * (points[2] - points[0]);
double b1 = 2 * (points[3] - points[1]);
double c1 = Math.pow(points[0], 2) - Math.pow(points[2], 2) +
Math.pow(points[1], 2) - Math.pow(points[3], 2);
double a2 = 2 * (points[4] - points[0]);
double b2 = 2 * (points[5] - points[1]);
double c2 = Math.pow(points[0], 2) - Math.pow(points[4], 2) +
Math.pow(points[1], 2) - Math.pow(points[5], 2);
double x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
double y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
System.out.println(String.format(
"%.3f %.3f %.3f", Math.round(x * 1000) / 1000.0,
Math.round(y * 1000) / 1000.0, Math.round(R * 1000) / 1000.0));
}
}
|
[["-", 51, 16, 12, 23, 0, 16, 31, 504, 71, 499], ["+", 51, 16, 12, 23, 0, 16, 31, 504, 71, 499], ["-", 51, 16, 12, 23, 0, 16, 12, 504, 71, 499], ["+", 51, 16, 12, 23, 0, 16, 12, 504, 71, 499], ["-", 31, 16, 12, 492, 3, 4, 0, 504, 71, 499], ["+", 31, 16, 12, 492, 3, 4, 0, 504, 71, 499]]
| 3
| 641
| 8
|
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Main {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
ArrayList<Double> inputs = new ArrayList<Double>(6);
ArrayList<Double> resultsX = new ArrayList<Double>(5);
ArrayList<Double> resultsY = new ArrayList<Double>(5);
ArrayList<Double> resultsRadius = new ArrayList<Double>(5);
int numLines = sc.nextInt();
for (int n = 0; n < numLines; n++) {
setInputs(inputs);
resultsX.add(getPointX(inputs.get(0), inputs.get(1), inputs.get(2),
inputs.get(3), inputs.get(4), inputs.get(5)));
resultsY.add(getPointY(inputs.get(0), inputs.get(1), inputs.get(2),
inputs.get(3), inputs.get(4), inputs.get(5)));
resultsRadius.add(getDistance(inputs.get(0), inputs.get(1),
resultsX.get(n), resultsY.get(n)));
inputs.clear();
}
for (int n = 0; n < numLines; n++) {
System.out.printf("%.3f %.3f %.3f\n", resultsX.get(n), resultsY.get(n),
resultsRadius.get(n));
}
}
private static void setInputs(ArrayList<Double> list) {
list.add(sc.nextDouble());
list.add(sc.nextDouble());
list.add(sc.nextDouble());
list.add(sc.nextDouble());
list.add(sc.nextDouble());
list.add(sc.nextDouble());
}
private static double getPointX(double x1, double y1, double x2, double y2,
double x3, double y3) {
double a1 = 2 * (x2 - x1);
double b1 = 2 * (y2 - y1);
double c1 = (x1 * x1) - (x2 * x2) + (y1 * y1) - (y2 * y2);
double a2 = 2 * (x3 - x1);
double b2 = 2 * (y3 - y1);
double c2 = (x1 * x1) - (x3 * x3) + (y1 * y1) - (y3 * y3);
double numerator = b1 * c2 - b2 * c1;
double denominator = a1 * b2 - a2 * b1;
return numerator / denominator;
}
private static double getPointY(double x1, double y1, double x2, double y2,
double x3, double y3) {
double a1 = 2 * (x2 - x1);
double b1 = 2 * (y2 - y1);
double c1 = (x1 * x1) - (x2 * x2) + (y1 * y1) - (y2 * y2);
double a2 = 2 * (x3 - x1);
double b2 = 2 * (y3 - y1);
double c2 = (x1 * x1) - (x3 * x3) + (y1 * y1) - (y3 * y3);
double numerator = b1 * c2 - b2 * c1;
double denominator = a1 * b2 - a2 * b1;
return numerator / denominator;
}
public static double getDistance(double x1, double y1, double x2, double y2) {
double distanceX = getDistanceX(x1, x2);
double squareX = distanceX * distanceX;
double distanceY = getDistanceY(y1, y2);
double squareY = distanceY * distanceY;
return Math.sqrt(squareX + squareY);
}
private static double getDistanceX(double x1, double x2) {
double distanceX = x1 - x2;
if (distanceX < 0) {
distanceX = distanceX * (-1);
}
return distanceX;
}
private static double getDistanceY(double y1, double y2) {
double distanceY = y1 - y2;
if (distanceY < 0) {
distanceY = distanceY * (-1);
}
return distanceY;
}
}
|
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Main {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
ArrayList<Double> inputs = new ArrayList<Double>(6);
ArrayList<Double> resultsX = new ArrayList<Double>(5);
ArrayList<Double> resultsY = new ArrayList<Double>(5);
ArrayList<Double> resultsRadius = new ArrayList<Double>(5);
int numLines = sc.nextInt();
for (int n = 0; n < numLines; n++) {
setInputs(inputs);
resultsX.add(getPointX(inputs.get(0), inputs.get(1), inputs.get(2),
inputs.get(3), inputs.get(4), inputs.get(5)));
resultsY.add(getPointY(inputs.get(0), inputs.get(1), inputs.get(2),
inputs.get(3), inputs.get(4), inputs.get(5)));
resultsRadius.add(getDistance(inputs.get(0), inputs.get(1),
resultsX.get(n), resultsY.get(n)));
inputs.clear();
}
for (int n = 0; n < numLines; n++) {
System.out.printf("%.3f %.3f %.3f\n", resultsX.get(n), resultsY.get(n),
resultsRadius.get(n));
}
}
private static void setInputs(ArrayList<Double> list) {
list.add(sc.nextDouble());
list.add(sc.nextDouble());
list.add(sc.nextDouble());
list.add(sc.nextDouble());
list.add(sc.nextDouble());
list.add(sc.nextDouble());
}
private static double getPointX(double x1, double y1, double x2, double y2,
double x3, double y3) {
double a1 = 2 * (x2 - x1);
double b1 = 2 * (y2 - y1);
double c1 = (x1 * x1) - (x2 * x2) + (y1 * y1) - (y2 * y2);
double a2 = 2 * (x3 - x1);
double b2 = 2 * (y3 - y1);
double c2 = (x1 * x1) - (x3 * x3) + (y1 * y1) - (y3 * y3);
double numerator = b1 * c2 - b2 * c1;
double denominator = a1 * b2 - a2 * b1;
return numerator / denominator;
}
private static double getPointY(double x1, double y1, double x2, double y2,
double x3, double y3) {
double a1 = 2 * (x2 - x1);
double b1 = 2 * (y2 - y1);
double c1 = (x1 * x1) - (x2 * x2) + (y1 * y1) - (y2 * y2);
double a2 = 2 * (x3 - x1);
double b2 = 2 * (y3 - y1);
double c2 = (x1 * x1) - (x3 * x3) + (y1 * y1) - (y3 * y3);
double numerator = c1 * a2 - c2 * a1;
double denominator = a1 * b2 - a2 * b1;
return numerator / denominator;
}
public static double getDistance(double x1, double y1, double x2, double y2) {
double distanceX = getDistanceX(x1, x2);
double squareX = distanceX * distanceX;
double distanceY = getDistanceY(y1, y2);
double squareY = distanceY * distanceY;
return Math.sqrt(squareX + squareY);
}
private static double getDistanceX(double x1, double x2) {
double distanceX = x1 - x2;
if (distanceX < 0) {
distanceX = distanceX * (-1);
}
return distanceX;
}
private static double getDistanceY(double y1, double y2) {
double distanceY = y1 - y2;
if (distanceY < 0) {
distanceY = distanceY * (-1);
}
return distanceY;
}
}
|
[["-", 0, 503, 49, 200, 51, 16, 31, 16, 31, 22], ["+", 0, 503, 49, 200, 51, 16, 31, 16, 31, 22], ["-", 0, 503, 49, 200, 51, 16, 31, 16, 12, 22], ["+", 0, 503, 49, 200, 51, 16, 31, 16, 12, 22], ["-", 0, 503, 49, 200, 51, 16, 12, 16, 31, 22], ["+", 0, 503, 49, 200, 51, 16, 12, 16, 31, 22], ["-", 0, 503, 49, 200, 51, 16, 12, 16, 12, 22], ["+", 0, 503, 49, 200, 51, 16, 12, 16, 12, 22]]
| 3
| 854
| 8
|
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static int N;
public static void main(String[] args) {
N = sc.nextInt();
double[] x = new double[3], y = new double[3];
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
x[j] = sc.nextDouble();
y[j] = sc.nextDouble();
}
double a = Math.hypot(x[0] - x[1], y[0] - y[1]),
b = Math.hypot(x[1] - x[2], y[1] - y[2]),
c = Math.hypot(x[2] - x[0], y[2] - y[0]),
R = a * b * c /
(Math.sqrt((a + b + c) * (-a + b + c) * (a - b + c) *
(a + b - c))),
aA = Math.acos((b * b + c * c - a * a) / (2.0 * b * c)),
aB = Math.acos((c * c + a * a - b * b) / (2.0 * c * a)),
aC = Math.acos((a * a + b * b - c * c) / (2.0 * a * b)),
A = Math.sin(2.0 * aA), B = Math.sin(2.0 * aB),
C = Math.sin(2.0 * aC),
xp = ((x[2] * A + x[0] * B + x[1] * C) / (A + B + C)),
yp = ((y[2] * A + y[0] * B + y[1] * C) / (A + B + C));
System.out.printf("%.3f %.3f %.3fn", xp, yp, R);
}
}
}
|
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static int N;
public static void main(String[] args) {
N = sc.nextInt();
double[] x = new double[3], y = new double[3];
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
x[j] = sc.nextDouble();
y[j] = sc.nextDouble();
}
double a = Math.hypot(x[0] - x[1], y[0] - y[1]),
b = Math.hypot(x[1] - x[2], y[1] - y[2]),
c = Math.hypot(x[2] - x[0], y[2] - y[0]),
R = a * b * c /
(Math.sqrt((a + b + c) * (-a + b + c) * (a - b + c) *
(a + b - c))),
aA = Math.acos((b * b + c * c - a * a) / (2.0 * b * c)),
aB = Math.acos((c * c + a * a - b * b) / (2.0 * c * a)),
aC = Math.acos((a * a + b * b - c * c) / (2.0 * a * b)),
A = Math.sin(2.0 * aA), B = Math.sin(2.0 * aB),
C = Math.sin(2.0 * aC),
xp = ((x[2] * A + x[0] * B + x[1] * C) / (A + B + C)),
yp = ((y[2] * A + y[0] * B + y[1] * C) / (A + B + C));
System.out.printf("%.3f %.3f %.3f\n", xp, yp, R);
}
}
}
|
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 44]]
| 3
| 458
| 3
|
import java.util.*;
public class Main {
static double[] solve(double a, double b, double c, double d, double e,
double f) {
double det = a * e - b * d;
double[] ans = new double[2];
ans[0] = (c * e - b * f) / det;
ans[1] = (a * f - c * d) / det;
for (int i = 0; i < 2; i++)
if (ans[i] == -0)
ans[i] = 0;
return ans;
}
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int n = stdIn.nextInt();
for (int i = 0; i < n; i++) {
double x1 = stdIn.nextDouble();
double y1 = stdIn.nextDouble();
double x2 = stdIn.nextDouble();
double y2 = stdIn.nextDouble();
double x3 = stdIn.nextDouble();
double y3 = stdIn.nextDouble();
double[] ans = solve(x1 - x2, y1 - y2, x1 * (x1 - x2) + y1 * (y1 - y2),
x3 - x2, y3 - y2, x3 * (x3 - x2) + y3 * (y3 - y2));
double xp, yp, r;
xp = (x2 + ans[0]) / 2.0;
yp = (y2 + ans[1]) / 2.0;
r = Math.sqrt((xp - x2) * (xp - x2) + (yp - x2) * (yp - x2));
System.out.printf("%.3f %.3f %.3f", xp, yp, r);
System.out.println();
}
}
}
|
import java.util.*;
public class Main {
static double[] solve(double a, double b, double c, double d, double e,
double f) {
double det = a * e - b * d;
double[] ans = new double[2];
ans[0] = (c * e - b * f) / det;
ans[1] = (a * f - c * d) / det;
for (int i = 0; i < 2; i++)
if (ans[i] == -0)
ans[i] = 0;
return ans;
}
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int n = stdIn.nextInt();
for (int i = 0; i < n; i++) {
double x1 = stdIn.nextDouble();
double y1 = stdIn.nextDouble();
double x2 = stdIn.nextDouble();
double y2 = stdIn.nextDouble();
double x3 = stdIn.nextDouble();
double y3 = stdIn.nextDouble();
double[] ans = solve(x1 - x2, y1 - y2, x1 * (x1 - x2) + y1 * (y1 - y2),
x3 - x2, y3 - y2, x3 * (x3 - x2) + y3 * (y3 - y2));
double xp, yp, r;
xp = (x2 + ans[0]) / 2.0;
yp = (y2 + ans[1]) / 2.0;
r = Math.sqrt((xp - x2) * (xp - x2) + (yp - y2) * (yp - y2));
System.out.printf("%.3f %.3f %.3f", xp, yp, r);
System.out.println();
}
}
}
|
[["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 16, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 12, 22]]
| 3
| 375
| 4
|
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int N = cin.nextInt();
for (; N-- != 0;) {
double x1 = cin.nextDouble();
double y1 = cin.nextDouble();
double x2 = cin.nextDouble();
double y2 = cin.nextDouble();
double x3 = cin.nextDouble();
double y3 = cin.nextDouble();
double p = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
(y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) /
(2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
double q = ((x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) -
(x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) /
(2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3));
double dist = Math.sqrt(Math.pow(x1 - p, 2) + Math.pow(y2 - q, 2));
BigDecimal ans1 = new BigDecimal(String.valueOf(p));
BigDecimal ans2 = new BigDecimal(String.valueOf(q));
BigDecimal ans3 = new BigDecimal(String.valueOf(dist));
p = ans1.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
q = ans2.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
dist = ans3.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
System.out.printf("%.3f ", p);
System.out.printf("%.3f ", q);
System.out.printf("%.3f\n", dist);
// System.out.println(ans(p)+" "+ans(q)+"
//"+ans(dist));
}
}
static String ans(double a) {
String s = String.valueOf(a);
for (; s.length() != 5;) {
s = s + "0";
}
return s;
}
}
|
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int N = cin.nextInt();
for (; N-- != 0;) {
double x1 = cin.nextDouble();
double y1 = cin.nextDouble();
double x2 = cin.nextDouble();
double y2 = cin.nextDouble();
double x3 = cin.nextDouble();
double y3 = cin.nextDouble();
double p = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
(y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) /
(2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
double q = ((x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) -
(x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) /
(2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3));
double dist = Math.sqrt(Math.pow(x1 - p, 2) + Math.pow(y1 - q, 2));
BigDecimal ans1 = new BigDecimal(String.valueOf(p));
BigDecimal ans2 = new BigDecimal(String.valueOf(q));
BigDecimal ans3 = new BigDecimal(String.valueOf(dist));
p = ans1.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
q = ans2.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
dist = ans3.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
System.out.printf("%.3f ", p);
System.out.printf("%.3f ", q);
System.out.printf("%.3f\n", dist);
// System.out.println(ans(p)+" "+ans(q)+"
//"+ans(dist));
}
}
static String ans(double a) {
String s = String.valueOf(a);
for (; s.length() != 5;) {
s = s + "0";
}
return s;
}
}
|
[["-", 0, 16, 12, 492, 3, 4, 0, 16, 31, 22], ["+", 0, 16, 12, 492, 3, 4, 0, 16, 31, 22]]
| 3
| 492
| 2
|
import java.awt.geom.Point2D;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n;
Point2D.Double a, b, c;
Point2D.Double middle1, middle2;
double slope1, slope2;
Point2D.Double solve;
double r;
n = sc.nextInt();
for (int i = 0; i < n; i++) {
a = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
b = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
c = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
middle1 = new Point2D.Double((a.x + b.x) / 2.0, (a.y + b.y) / 2.0);
middle2 = new Point2D.Double((b.x + c.x) / 2.0, (b.y + c.y) / 2.0);
slope1 = getSlope(a, b);
slope2 = getSlope(b, c);
solve = makeSolution(middle1, slope1, middle2, slope2);
r = Math.sqrt((solve.x - a.x) * (solve.x - a.x) +
(solve.y - a.y) * (solve.y - a.y));
System.out.printf("%.3f %.3f %.3f", solve.x, solve.y, r);
}
}
public static double getSlope(Point2D.Double a, Point2D.Double b) {
if (a.y == b.y) {
return Double.POSITIVE_INFINITY;
}
return (b.x - a.x) / (b.y - a.y);
}
public static Point2D.Double makeSolution(Point2D.Double p1, double e1,
Point2D.Double p2, double e2) {
double a, b, c, d;
double x = 0, y = 0;
a = e1;
if (!Double.isInfinite(a)) {
b = p1.y - a * p1.x;
} else {
b = Double.NaN;
}
c = e2;
if (!Double.isInfinite(c)) {
d = p2.y - c * p2.x;
} else {
d = Double.NaN;
}
if (!Double.isNaN(b) && !Double.isNaN(d)) {
x = (d - b) / (a - c);
y = (a * d - b * c) / (a - c);
} else if (Double.isNaN(b)) {
x = p1.x;
y = c * x + d;
} else if (Double.isNaN(d)) {
x = p2.x;
y = a * x + b;
}
return new Point2D.Double(x, y);
}
}
|
import java.awt.geom.Point2D;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n;
Point2D.Double a, b, c;
Point2D.Double middle1, middle2;
double slope1, slope2;
Point2D.Double solve;
double r;
n = sc.nextInt();
for (int i = 0; i < n; i++) {
a = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
b = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
c = new Point2D.Double(sc.nextDouble(), sc.nextDouble());
middle1 = new Point2D.Double((a.x + b.x) / 2.0, (a.y + b.y) / 2.0);
middle2 = new Point2D.Double((b.x + c.x) / 2.0, (b.y + c.y) / 2.0);
slope1 = getSlope(a, b);
slope2 = getSlope(b, c);
solve = makeSolution(middle1, slope1, middle2, slope2);
r = Math.sqrt((solve.x - a.x) * (solve.x - a.x) +
(solve.y - a.y) * (solve.y - a.y));
System.out.printf("%.3f %.3f %.3f\n", solve.x, solve.y, r);
}
}
public static double getSlope(Point2D.Double a, Point2D.Double b) {
if (a.y == b.y) {
return Double.POSITIVE_INFINITY;
}
return -(b.x - a.x) / (b.y - a.y);
}
public static Point2D.Double makeSolution(Point2D.Double p1, double e1,
Point2D.Double p2, double e2) {
double a, b, c, d;
double x = 0.0, y = 0.0;
a = e1;
if (!Double.isInfinite(a)) {
b = p1.y - a * p1.x;
} else {
b = Double.NaN;
}
c = e2;
if (!Double.isInfinite(c)) {
d = p2.y - c * p2.x;
} else {
d = Double.NaN;
}
if (!Double.isNaN(b) && !Double.isNaN(d)) {
x = (d - b) / (a - c);
y = (a * d - b * c) / (a - c);
} else if (Double.isNaN(b)) {
x = p1.x;
y = c * x + d;
} else if (Double.isNaN(d)) {
x = p2.x;
y = a * x + b;
}
return new Point2D.Double(x, y);
}
}
|
[["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 44], ["+", 8, 196, 0, 37, 0, 16, 31, 91, 17, 33], ["-", 0, 195, 8, 196, 0, 503, 49, 200, 51, 499], ["+", 0, 195, 8, 196, 0, 503, 49, 200, 51, 515]]
| 3
| 610
| 6
|
#include <math.h>
#include <stdio.h>
int main() {
int i, n;
double x1, y1, x2, y2, x3, y3, x, y, a, b, c, d, e, f;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lg %lg %lg %lg %lg %lg", &x1, &y1, &x2, &y2, &x3, &y3);
x2 -= x1;
y2 -= y1;
x3 -= x1;
y3 -= y1;
a = x2;
b = y2;
c = x2 / 2 * x2 + y2 / 2 * y2;
d = x3;
e = y3;
f = x3 / 2 * x3 + y3 / 2 * y3;
x = (c * e - b * f) / (a * e - b * d);
y = (c * d - a * f) / (b * d - a * e);
if (-0.0005 < x && x < 0.0005)
x = 0;
if (-0.0005 < y && y < 0.0005)
y = 0;
printf("%.3f %.3f %.3f\n", x, y, sqrt(x * x + y * y));
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int i, n;
double x1, y1, x2, y2, x3, y3, x, y, a, b, c, d, e, f;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lg %lg %lg %lg %lg %lg", &x1, &y1, &x2, &y2, &x3, &y3);
x2 -= x1;
y2 -= y1;
x3 -= x1;
y3 -= y1;
a = x2;
b = y2;
c = x2 / 2 * x2 + y2 / 2 * y2;
d = x3;
e = y3;
f = x3 / 2 * x3 + y3 / 2 * y3;
x = (c * e - b * f) / (a * e - b * d);
y = (c * d - a * f) / (b * d - a * e);
if (-0.0005 < x && x < 0.0005)
x = 0;
if (-0.0005 < y && y < 0.0005)
y = 0;
printf("%.3f %.3f %.3f\n", x + x1, y + y1, sqrt(x * x + y * y));
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22]]
| 0
| 252
| 4
|
#include <math.h>
#include <stdio.h>
int main(void) {
double x1, x2, x3, y1, y2, y3, x, y, r, a, s;
int n;
scanf("%d", &n);
while ((n != 0) &&
(scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3) != EOF)) {
a = (sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) +
sqrt(x2 * x2 + y2 * y2) - sqrt(x3 * x3 - y3 * y3)) /
2 * sqrt(x1 * x1 + y1 * y1) * sqrt(x2 * x2 + y2 * y2);
s = sin(a);
r = x3 / (2 * s);
x = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
(y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) /
(2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
y = ((x1 - x3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
(x1 - x2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) /
(2 * (y1 - y2) * (x1 - x3) - 2 * (y1 - y3) * (x1 - x2));
r = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
printf("%f %.3f %.3f\n", x, y, r);
n--;
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
double x1, x2, x3, y1, y2, y3, x, y, r, a, s;
int n;
scanf("%d", &n);
while ((n != 0) &&
(scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3) != EOF)) {
a = (sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) +
sqrt(x2 * x2 + y2 * y2) - sqrt(x3 * x3 - y3 * y3)) /
2 * sqrt(x1 * x1 + y1 * y1) * sqrt(x2 * x2 + y2 * y2);
s = sin(a);
r = x3 / (2 * s);
x = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
(y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) /
(2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
y = ((x1 - x3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
(x1 - x2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) /
(2 * (y1 - y2) * (x1 - x3) - 2 * (y1 - y3) * (x1 - x2));
r = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
printf("%.3f %.3f %.3f\n", x, y, r);
n--;
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 393
| 2
|
#include <math.h>
#include <stdio.h>
int main() {
int n;
double x1, y1, x2, y2, x3, y3, a, b, c, s, q, sina, r, px, py;
scanf("%d", &n);
while (n--) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
a = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
b = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
c = sqrt(pow(x2 - x3, 2) + pow(y2 - y3, 2));
q = (a + b + c) / 2;
r = sqrt(s * (s - a) * (s - b) * (s - c));
sina = 2 * q / b / c;
r = a / sina / 2;
a = a * a;
b = b * b;
c = c * c;
px = (a * (b + c - a) * x3 + b * (a + c - b) * x2 + c * (a + b - c) * x1) /
16 / pow(q, 2);
py = (a * (b + c - a) * y3 + b * (a + c - b) * y2 + c * (a + b - c) * y1) /
16 / pow(q, 2);
printf("%.3f %.3f %.3f\n", px, py, r);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int n;
double x1, y1, x2, y2, x3, y3, a, b, c, s, q, sina, r, px, py;
scanf("%d", &n);
while (n--) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
a = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
b = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
c = sqrt(pow(x2 - x3, 2) + pow(y2 - y3, 2));
s = (a + b + c) / 2;
q = sqrt(s * (s - a) * (s - b) * (s - c));
sina = 2 * q / b / c;
r = a / sina / 2;
a = a * a;
b = b * b;
c = c * c;
px = (a * (b + c - a) * x3 + b * (a + c - b) * x2 + c * (a + b - c) * x1) /
16 / pow(q, 2);
py = (a * (b + c - a) * y3 + b * (a + c - b) * y2 + c * (a + b - c) * y1) /
16 / pow(q, 2);
printf("%.3f %.3f %.3f\n", px, py, r);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22]]
| 0
| 343
| 4
|
#include <math.h>
#include <stdio.h>
int main();
double sq(double);
int main() {
double x1, x2, x3, y1, y2, y3, a1, b1, c1, a2, b2, c2, x, y, r, dx, dy;
int n, i;
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf\n", &x1, &y1, &x2, &y2, &x3, &y3);
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = sq(x1) - sq(x2) + sq(y1) - sq(y2);
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = sq(x1) - sq(x3) + sq(y1) - sq(y3);
x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
dx = fabs(x - x1);
dy = fabs(y - y1);
r = sqrt(dx + dy);
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
return 0;
}
double sq(double x) { return pow(x, 2); }
|
#include <math.h>
#include <stdio.h>
int main();
double sq(double);
int main() {
double x1, x2, x3, y1, y2, y3, a1, b1, c1, a2, b2, c2, x, y, r, dx, dy;
int n, i;
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf\n", &x1, &y1, &x2, &y2, &x3, &y3);
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = sq(x1) - sq(x2) + sq(y1) - sq(y2);
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = sq(x1) - sq(x3) + sq(y1) - sq(y3);
x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
dx = fabs(x - x1);
dy = fabs(y - y1);
r = sqrt(sq(dx) + sq(dy));
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
return 0;
}
double sq(double x) { return pow(x, 2); }
|
[["+", 12, 2, 3, 4, 0, 16, 31, 2, 63, 22], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 24], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 25], ["+", 12, 2, 3, 4, 0, 16, 12, 2, 63, 22], ["+", 3, 4, 0, 16, 12, 2, 3, 4, 0, 24], ["+", 3, 4, 0, 16, 12, 2, 3, 4, 0, 25]]
| 0
| 301
| 6
|
#include <math.h>
#include <stdio.h>
int main() {
int i, n;
double x1, x2, x3, y1, y2, y3;
double a, b, c, d, e, f;
double X1, Y1, r;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
a = 2 * (x2 - x1);
b = 2 * (y2 - y1);
c = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
d = 2 * (x3 - x1);
e = 2 * (y3 - y1);
f = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
X1 = (b * f - e * c) / (a * e - d * b);
Y1 = (c * d - f * a) / (a * d - d * b);
r = sqrt((X1 - x1) * (X1 - x1) + (Y1 - y1) * (Y1 - y1));
X1 *= 1000;
Y1 *= 1000;
r *= 1000;
X1 = (int)(X1 > 0.0 ? X1 + 0.5 : X1 - 0.5);
Y1 = (int)(Y1 > 0.0 ? Y1 + 0.5 : Y1 - 0.5);
r = (int)(r > 0.0 ? r + 0.5 : r - 0.5);
X1 = (double)X1 / 1000;
Y1 = (double)Y1 / 1000;
r = (double)r / 1000;
printf("%.3f %.3f %.3f\n", X1, Y1, r);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int i, n;
double x1, x2, x3, y1, y2, y3;
double a, b, c, d, e, f;
double X1, Y1, r;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
a = 2 * (x2 - x1);
b = 2 * (y2 - y1);
c = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
d = 2 * (x3 - x1);
e = 2 * (y3 - y1);
f = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
X1 = (b * f - e * c) / (a * e - d * b);
Y1 = (c * d - f * a) / (a * e - d * b);
r = sqrt((X1 - x1) * (X1 - x1) + (Y1 - y1) * (Y1 - y1));
X1 *= 1000;
Y1 *= 1000;
r *= 1000;
X1 = (int)(X1 > 0.0 ? X1 + 0.5 : X1 - 0.5);
Y1 = (int)(Y1 > 0.0 ? Y1 + 0.5 : Y1 - 0.5);
r = (int)(r > 0.0 ? r + 0.5 : r - 0.5);
X1 = (double)X1 / 1000;
Y1 = (double)Y1 / 1000;
r = (double)r / 1000;
printf("%.3f %.3f %.3f\n", X1, Y1, r);
}
return 0;
}
|
[["-", 12, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 12, 16, 12, 23, 0, 16, 31, 16, 12, 22]]
| 0
| 360
| 2
|
#include <math.h>
#include <stdio.h>
int main() {
int n, i;
double x1, x2, x3, y1, y2, y3;
double x, y, r;
double a, b;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
if (y1 == y2) {
a = (x2 * x2 + y2 * y2 - (x3 * x3 + y3 * y3)) / (2 * (y2 - y3));
b = (x3 * x3 + y3 * y3 - (x1 * x1 + y1 * y1)) / (2 * (y3 - y1));
x = (a - b) / ((x1 - x3) / (y3 - y1) - (x3 - x2) / (y2 - y3));
y = (x3 - x2) / (y2 - y3) * x + a;
} else if (y2 == y3) {
a = (x1 * x1 + y1 * y1 - (x2 * x2 + y2 * y2)) / (2 * (y1 - y2));
b = (x3 * x3 + y3 * y3 - (x1 * x1 + y1 * y1)) / (2 * (y3 - y1));
x = (a - b) / ((x1 - x3) / (y3 - y1) - (x2 - x1) / (y1 - y2));
y = (x2 - x1) / (y1 - y2) * x + a;
} else if (y3 == y1) {
a = (x2 * x2 + y2 * y2 - (x3 * x3 + y3 * y3)) / (2 * (y2 - y3));
b = (x1 * x1 + y1 * y1 - (x2 * x2 + y2 * y2)) / (2 * (y1 - y2));
x = (a - b) / ((x2 - x1) / (y1 - y2) - (x3 - x2) / (y2 - y3));
y = (x2 - x1) / (y1 - y2) * x + a;
} else {
a = (x2 * x2 + y2 * y2 - (x3 * x3 + y3 * y3)) / (2 * (y2 - y3));
b = (x1 * x1 + y1 * y1 - (x2 * x2 + y2 * y2)) / (2 * (y1 - y2));
x = (a - b) / ((x2 - x1) / (y1 - y2) - (x3 - x2) / (y2 - y3));
y = (x2 - x1) / (y1 - y2) * x + a;
}
r = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int n, i;
double x1, x2, x3, y1, y2, y3;
double x, y, r;
double a, b;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
if (y1 == y2) {
a = (x2 * x2 + y2 * y2 - (x3 * x3 + y3 * y3)) / (2 * (y2 - y3));
b = (x3 * x3 + y3 * y3 - (x1 * x1 + y1 * y1)) / (2 * (y3 - y1));
x = (a - b) / ((x1 - x3) / (y3 - y1) - (x3 - x2) / (y2 - y3));
y = (x3 - x2) / (y2 - y3) * x + a;
} else if (y2 == y3) {
a = (x1 * x1 + y1 * y1 - (x2 * x2 + y2 * y2)) / (2 * (y1 - y2));
b = (x3 * x3 + y3 * y3 - (x1 * x1 + y1 * y1)) / (2 * (y3 - y1));
x = (a - b) / ((x1 - x3) / (y3 - y1) - (x2 - x1) / (y1 - y2));
y = (x2 - x1) / (y1 - y2) * x + a;
} else if (y3 == y1) {
a = (x2 * x2 + y2 * y2 - (x3 * x3 + y3 * y3)) / (2 * (y2 - y3));
b = (x1 * x1 + y1 * y1 - (x2 * x2 + y2 * y2)) / (2 * (y1 - y2));
x = (a - b) / ((x2 - x1) / (y1 - y2) - (x3 - x2) / (y2 - y3));
y = (x2 - x1) / (y1 - y2) * x + b;
} else {
a = (x2 * x2 + y2 * y2 - (x3 * x3 + y3 * y3)) / (2 * (y2 - y3));
b = (x1 * x1 + y1 * y1 - (x2 * x2 + y2 * y2)) / (2 * (y1 - y2));
x = (a - b) / ((x2 - x1) / (y1 - y2) - (x3 - x2) / (y2 - y3));
y = (x2 - x1) / (y1 - y2) * x + b;
}
r = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
return 0;
}
|
[["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
| 0
| 629
| 4
|
#include <math.h>
#include <stdio.h>
int main(void) {
double x1, x2, x3, y1, y2, y3;
int n;
double a1, b1, c1, a2, b2, c2, x, y, r;
scanf("%d", &n);
while (n--) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - y1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
r = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
printf("%.3lf %.3lf %.3lf\n", x, y, r);
fflush(stdin);
fflush(stdout);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
double x1, x2, x3, y1, y2, y3;
int n;
double a1, b1, c1, a2, b2, c2, x, y, r;
scanf("%d", &n);
while (n--) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
r = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
printf("%.3lf %.3lf %.3lf\n", x, y, r);
fflush(stdin);
fflush(stdout);
}
return 0;
}
|
[["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22]]
| 0
| 264
| 2
|
#include <math.h>
#include <stdio.h>
#define SQ(X) ((X) * (X))
#define SQDIST(X1, Y1, X2, Y2) (SQ((X2) - (X1)) + SQ((Y2) - (Y1)))
#define DIST(X1, Y1, X2, Y2) (sqrt(SQDIST(X1, Y1, X2, Y2)))
/** Application main entry point. */
int main(int argc, char *argv[]) {
int n;
scanf("%d", &n);
while (n--) {
double x1, x2, x3, y1, y2, y3;
double A[2][2], detA;
double B[2];
double C[2];
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
A[0][0] = 2 * x2 - 2 * x1;
A[1][0] = 2 * x3 - 2 * x1;
A[0][1] = 2 * y2 - 2 * y1;
A[1][1] = 2 * y3 - 2 * y1;
detA = A[0][0] * A[1][1] - A[0][1] * A[1][0];
B[0] = SQ(x2) + SQ(y2) - SQ(x1) - SQ(y1);
B[1] = SQ(x3) + SQ(y3) - SQ(x1) - SQ(y1);
C[0] = (B[0] * A[1][1] - A[0][1] * B[1]) / detA;
C[1] = (A[0][0] * B[1] - B[0] * A[1][0]) / detA;
printf("%.3lf %.3lf %.3lf\n", C[0], C[1], DIST(C[0], C[1], x1, x2));
}
return (0);
}
|
#include <math.h>
#include <stdio.h>
#define SQ(X) ((X) * (X))
#define SQDIST(X1, Y1, X2, Y2) (SQ((X2) - (X1)) + SQ((Y2) - (Y1)))
#define DIST(X1, Y1, X2, Y2) (sqrt(SQDIST(X1, Y1, X2, Y2)))
/** Application main entry point. */
int main(int argc, char *argv[]) {
int n;
scanf("%d", &n);
while (n--) {
double x1, x2, x3, y1, y2, y3;
double A[2][2], detA;
double B[2];
double C[2];
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
A[0][0] = 2 * x2 - 2 * x1;
A[1][0] = 2 * x3 - 2 * x1;
A[0][1] = 2 * y2 - 2 * y1;
A[1][1] = 2 * y3 - 2 * y1;
detA = A[0][0] * A[1][1] - A[0][1] * A[1][0];
B[0] = SQ(x2) + SQ(y2) - SQ(x1) - SQ(y1);
B[1] = SQ(x3) + SQ(y3) - SQ(x1) - SQ(y1);
C[0] = (B[0] * A[1][1] - A[0][1] * B[1]) / detA;
C[1] = (A[0][0] * B[1] - B[0] * A[1][0]) / detA;
printf("%.3lf %.3lf %.3lf\n", C[0], C[1], DIST(C[0], C[1], x1, y1));
}
return (0);
}
|
[["-", 0, 2, 3, 4, 0, 2, 3, 4, 0, 22], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 22]]
| 0
| 388
| 2
|
main() {
double a, b, c, d, e, f, g, h, i, x, y;
for (scanf("%*d"); ~scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f);
printf("%.3f %.3f %.3f\n", x, y, hypot(a - x, b - y)))
g = a * a + b * b, h = c * c + d * d, i = e * e + f * f,
x = (a * (h - i) + c * (i - g) + e * (g - h)) /
(y = a * (d - f) + c * (f - b) + e * (b - d)) / 2,
y = (b * (i - h) + d * (g - i) + f * (h - g)) / y / 2;
}
|
main() {
double a, b, c, d, e, f, g, h, i, x, y;
for (scanf("%*d"); ~scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f);
printf("%.3f %.3f %.3f\n", x, y, hypot(a - x, b - y)))
g = a * a + b * b, h = c * c + d * d, i = e * e + f * f,
y = (a * (h - i) + c * (i - g) + e * (g - h)) /
(x = a * (d - f) + c * (f - b) + e * (b - d)) / 2,
x = (b * (i - h) + d * (g - i) + f * (h - g)) / x / 2;
}
|
[["-", 12, 34, 12, 34, 12, 34, 31, 11, 31, 22], ["+", 12, 34, 12, 34, 12, 34, 31, 11, 31, 22], ["-", 12, 16, 31, 16, 12, 23, 0, 11, 31, 22], ["+", 12, 16, 31, 16, 12, 23, 0, 11, 31, 22], ["-", 12, 34, 12, 34, 12, 34, 12, 11, 31, 22], ["+", 12, 34, 12, 34, 12, 34, 12, 11, 31, 22], ["-", 12, 34, 12, 11, 12, 16, 31, 16, 12, 22], ["+", 12, 34, 12, 11, 12, 16, 31, 16, 12, 22]]
| 0
| 206
| 8
|
#include <math.h>
#include <stdio.h>
int main(void) {
int n;
float x1, x2, x3;
float y1, y2, y3;
float dx, dy;
float tx, ty, r;
float a1, b1, c1, a2, b2, c2;
scanf("%d", &n);
while (n > 0) {
n--;
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
dx = x1;
dy = y1;
//SÀWðßé
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
x1 *= x1;
x2 *= x2;
x3 *= x3;
y1 *= y1;
y2 *= y2;
y3 *= y3;
c1 = x1 - x2 + y1 - y2;
c2 = x1 - x3 + y1 - y3;
tx = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
ty = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
//¼aðßé
dx = dx - tx;
dx *= dx;
dy = dy - ty;
dy *= dy;
r = sqrt(dx + dy);
printf("%.3lf %.3lf %.3lf\n", tx, ty, r);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
int n;
double x1, x2, x3;
double y1, y2, y3;
double dx, dy;
double tx, ty, r;
double a1, b1, c1, a2, b2, c2;
scanf("%d", &n);
while (n > 0) {
n--;
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
dx = x1;
dy = y1;
//SÀWðßé
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
x1 *= x1;
x2 *= x2;
x3 *= x3;
y1 *= y1;
y2 *= y2;
y3 *= y3;
c1 = x1 - x2 + y1 - y2;
c2 = x1 - x3 + y1 - y3;
tx = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
ty = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
//¼aðßé
dx = dx - tx;
dx *= dx;
dy = dy - ty;
dy *= dy;
r = sqrt(dx + dy);
printf("%.3lf %.3lf %.3lf\n", tx, ty, r);
}
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40]]
| 0
| 283
| 10
|
#include <math.h>
#include <stdio.h>
int main(void) {
double x, y, r;
double x1, x2, x3, y1, y2, y3;
double ecm[3][2];
double a, b, A;
int i;
int n;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
ecm[0][0] = x1 - x2;
ecm[0][1] = y1 - y2;
ecm[0][2] = (x2 * x2 + y2 * y2) - (x1 * x1 + y1 * y1);
ecm[1][0] = x1 - x3;
ecm[1][1] = y1 - y3;
ecm[1][2] = (x3 * x3 + y3 * y3) - (x1 * x1 + y1 * y1);
A = (ecm[0][0] * ecm[1][1]) - (ecm[0][1] * ecm[1][0]);
a = ((ecm[0][2] * ecm[1][1]) - (ecm[0][1] * ecm[1][2])) / A + 0;
b = ((ecm[0][0] * ecm[1][2]) - (ecm[0][2] * ecm[1][0])) / A + 0;
x = (a / -2.0);
y = (b / -2.0);
r = sqrt(pow(x1 - x, 2) + pow(y1 - y, 2));
printf("%.3f %.3f %.3f\n", x, y, r);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
double x, y, r;
double x1, x2, x3, y1, y2, y3;
double ecm[2][3];
double a, b, A;
int i;
int n;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
ecm[0][0] = x1 - x2;
ecm[0][1] = y1 - y2;
ecm[0][2] = (x2 * x2 + y2 * y2) - (x1 * x1 + y1 * y1);
ecm[1][0] = x1 - x3;
ecm[1][1] = y1 - y3;
ecm[1][2] = (x3 * x3 + y3 * y3) - (x1 * x1 + y1 * y1);
A = (ecm[0][0] * ecm[1][1]) - (ecm[0][1] * ecm[1][0]);
a = ((ecm[0][2] * ecm[1][1]) - (ecm[0][1] * ecm[1][2])) / A + 0;
b = ((ecm[0][0] * ecm[1][2]) - (ecm[0][2] * ecm[1][0])) / A + 0;
x = (a / -2.0);
y = (b / -2.0);
r = sqrt(pow(x1 - x, 2) + pow(y1 - y, 2));
printf("%.3f %.3f %.3f\n", x, y, r);
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
| 0
| 389
| 4
|
w = gets.to_i
n = gets.to_i
horizon_bars = []
n.times do
horizon_bars << gets.split(',').map(&:to_i)
end
p horizon_bars
1.upto(w) do |i|
horizon_bars.reverse_each do |bar|
source = bar.index(i)
i = bar[(source + 1) % 2] if source
end
puts i
end
|
w = gets.to_i
n = gets.to_i
horizon_bars = []
n.times do
horizon_bars << gets.split(',').map(&:to_i)
end
1.upto(w) do |i|
horizon_bars.reverse_each do |bar|
source = bar.index(i)
i = bar[(source + 1) % 2] if source
end
puts i
end
|
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["-", 36, 36, 0, 493, 0, 652, 3, 4, 0, 22]]
| 4
| 80
| 2
|
class DrawingLots
def initialize(width, switch_ary)
@results = (1..width).to_a
switch_ary.each do |data|
tmp = @results[data[1] - 1]
@results[data[1] - 1] = @results[data[0] - 1]
@results[data[0] - 1] = tmp
end
end
attr_accessor :results
def all_result
@results
end
end
width = gets.to_i
switch_ary = []
gets.to_i.times do
switch_ary << gets.split(',').map(&:to_i)
end
puts DrawingLots.new(width, switch_ary).all_result.join(' ')
|
class DrawingLots
def initialize(width, switch_ary)
@results = (1..width).to_a
switch_ary.each do |data|
tmp = @results[data[1] - 1]
@results[data[1] - 1] = @results[data[0] - 1]
@results[data[0] - 1] = tmp
end
end
attr_accessor :results
def all_result
@results
end
end
width = gets.to_i
switch_ary = []
gets.to_i.times do
switch_ary << gets.split(',').map(&:to_i)
end
puts DrawingLots.new(width, switch_ary).all_result.join("\n")
|
[["-", 3, 4, 0, 652, 3, 4, 0, 557, 0, 62], ["-", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 62], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 44]]
| 4
| 125
| 6
|
w = gets.chomp.to_i
n = gets.chomp.to_i
array = []
a = []
b = []
(1..w).each do |j|
array[j] = j
end
(1..n).each do |_i|
a, b = gets.chomp.split
a = a.to_i
b = b.to_i
(1..w).each do |k|
next unless a == k
x = array[b]
array[b] = array[k]
array[k] = x
end
end
(1..w).each do |s|
puts array[s]
end
|
w = gets.chomp.to_i
n = gets.chomp.to_i
array = []
a = []
b = []
(1..w).each do |j|
array[j] = j
end
(1..n).each do |_i|
a, b = gets.chomp.split(',')
a = a.to_i
b = b.to_i
(1..w).each do |k|
next unless a == k
x = array[b]
array[b] = array[k]
array[k] = x
end
end
(1..w).each do |s|
puts array[s]
end
|
[["+", 8, 736, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 652, 3, 4, 0, 557, 0, 62], ["+", 0, 662, 12, 652, 3, 4, 0, 557, 0, 6], ["+", 8, 736, 0, 662, 12, 652, 3, 4, 0, 25]]
| 4
| 130
| 5
|
w = gets.to_i
n = gets.to_i
n_list = []
n.times.each do
st = gets.split(/\s/)
n_list << [st[0].to_i, st[1].to_i]
end
answers = []
1.upto(w).each do |i|
current_w = i
n_list.each do |n_line|
if current_w == n_line[0]
current_w = n_line[1]
elsif current_w == n_line[1]
current_w = n_line[0]
end
end
answers[current_w - 1] = i
end
puts answers
|
w = gets.to_i
n = gets.to_i
n_list = []
n.times.each do
st = gets.split(/,/)
n_list << [st[0].to_i, st[1].to_i]
end
answers = []
1.upto(w).each do |i|
current_w = i
n_list.each do |n_line|
if current_w == n_line[0]
current_w = n_line[1]
elsif current_w == n_line[1]
current_w = n_line[0]
end
end
answers[current_w - 1] = i
end
puts answers
|
[["-", 0, 662, 12, 652, 3, 4, 0, 575, 0, 44], ["+", 0, 662, 12, 652, 3, 4, 0, 575, 0, 6]]
| 4
| 113
| 2
|
w = gets.to_i
arr = w.times.map { |i| i + 1 }
gets.to_i.times do
a, b = str.split(',').map(&:to_i)
arr[a - 1], arr[b - 1] = arr[b - 1], arr[a - 1]
end
puts arr
|
w = gets.to_i
arr = w.times.map { |i| i + 1 }
gets.to_i.times do
a, b = gets.split(',').map(&:to_i)
arr[a - 1], arr[b - 1] = arr[b - 1], arr[a - 1]
end
puts arr
|
[["-", 8, 736, 0, 662, 12, 652, 486, 652, 486, 22], ["+", 8, 736, 0, 662, 12, 652, 486, 652, 486, 22]]
| 4
| 74
| 2
|
def swap(a, c)
a[c[0] - 1], a[c[1] - 1] = a[c[1] - 1], a[c[0] - 1]
a
end
w = gets.to_i
a = []
0.upto(w - 1) do |i|
a[i] = i + 1
end
n = gets.to_i
n.times do
c = gets.chomp.split(',').map(&:to_i)
a = swap(a, c)
p a
end
a.each { |v| puts v }
|
def swap(a, c)
a[c[0] - 1], a[c[1] - 1] = a[c[1] - 1], a[c[0] - 1]
a
end
w = gets.to_i
a = []
0.upto(w - 1) do |i|
a[i] = i + 1
end
n = gets.to_i
n.times do
c = gets.chomp.split(',').map(&:to_i)
a = swap(a, c)
end
a.each { |v| puts v }
|
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 22]]
| 4
| 126
| 2
|
l=range(1,eval(input())+1)
for a,b in[list(map(int,input().split(",")))for i in range(eval(input()))]:l[a-1],l[b-1]=l[b-1],l[a-1]
for i in l:print(i)
|
l=list(range(1,eval(input())+1))
for a,b in[list(map(int,input().split(",")))for i in range(eval(input()))]:l[a-1],l[b-1]=l[b-1],l[a-1]
for i in l:print(i)
|
[["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
| 5
| 89
| 3
|
w = int(raw_input())
n = int(raw_input())
l = [i for i in range(1,w+1)]
while n > 0:
a,b = map(int,raw_input().split(','))
l[a-1],l[b-1] = l[b-1],l[a-1]
n -= 1
for i in l:
print(i)
|
w = int(input())
n = int(input())
l = [i for i in range(1,w+1)]
while n > 0:
a,b = map(int,input().split(','))
l[a-1],l[b-1] = l[b-1],l[a-1]
n -= 1
for i in l:
print(i)
|
[["-", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["-", 3, 4, 0, 652, 63, 319, 500, 652, 63, 22], ["+", 3, 4, 0, 652, 63, 319, 500, 652, 63, 22]]
| 5
| 95
| 6
|
w = int(input())
n = int(input())
Ami = []
Num = []
for i in range(n):
Ami.append(list(map(int,input().split(","))))
print(Ami)
for i in range(1,w+1):
pos = i
for j in range(n):
if pos == Ami[j][0]:
pos = Ami[j][1]
elif pos == Ami[j][1]:
pos = Ami[j][0]
Num.append([pos,i])
Num = sorted(Num)
for k in range(0,w):
print(Num[k][1])
|
w = int(input())
n = int(input())
Ami = []
Num = []
for i in range(n):
Ami.append(list(map(int,input().split(","))))
for i in range(1,w+1):
pos = i
for j in range(n):
if pos == Ami[j][0]:
pos = Ami[j][1]
elif pos == Ami[j][1]:
pos = Ami[j][0]
Num.append([pos,i])
Num = sorted(Num)
for k in range(0,w):
print(Num[k][1])
|
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 158
| 4
|
import sys
n = int(sys.stdin.readline().rstrip())
m = int(sys.stdin.readline().rstrip())
l = []
for i in range(m):
l.append(list(map(int, sys.stdin.readline().rstrip().split(','))))
print(l)
for i in range(n):
cur = i+1
for d in l[::-1]:
if cur in d:
cur = d[0] if cur == d[1] else d[1]
print(cur)
|
import sys
n = int(sys.stdin.readline().rstrip())
m = int(sys.stdin.readline().rstrip())
l = []
for i in range(m):
l.append(list(map(int, sys.stdin.readline().rstrip().split(','))))
for i in range(n):
cur = i+1
for d in l[::-1]:
if cur in d:
cur = d[0] if cur == d[1] else d[1]
print(cur)
|
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 132
| 4
|
w = int(input())
nums = list(range(w + 1))
for _ in range(int(input())):
a, b = map(int, input().split(", "))
nums[a], nums[b] = nums[b], nums[a]
for x in nums[1:]:
print(x)
|
w = int(input())
nums = list(range(w + 1))
for _ in range(int(input())):
a, b = map(int, input().split(","))
nums[a], nums[b] = nums[b], nums[a]
for x in nums[1:]:
print(x)
|
[["-", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6]]
| 5
| 83
| 2
|
a=list(range(int(input())+1))
for _ in[0]*int(input()):
s,t=map(int,input().split(','))
a[s],a[t]=a[t],a[s]
for s in a:
if s:print(s+1)
|
a=list(range(int(input())+1))
for _ in[0]*int(input()):
s,t=map(int,input().split(','));a[s],a[t]=a[t],a[s]
for s in a:
if s:print(s)
|
[["+", 36, 36, 0, 656, 0, 7, 8, 196, 0, 35], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 82
| 3
|
a=list(range(int(input())+1))
for _ in[0]*int(input()):
s,t=map(int,input().split(','))
a[s],a[t]=a[t],a[s]
for s in a:print(s+1)
|
a=list(range(int(input())+1))
for _ in[0]*int(input()):s,t=map(int,input().split(','));a[s],a[t]=a[t],a[s]
for s in a:s and print(s)
|
[["+", 36, 36, 0, 656, 0, 7, 8, 196, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 679, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 679, 17, 355], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 79
| 5
|
import math
tate =int(input())
yoko=int(input())
arr = [i+1 for i in range(tate)]
for j in range(yoko):
rep1,rep2=input().split();
rep1=int(rep1)-1
rep2=int(rep2)-1
arr[rep1],arr[rep2] = arr[rep2],arr[rep1]
for k in range(tate):
print(arr[k])
|
tate =int(input())
yoko=int(input())
arr = [i+1 for i in range(tate)]
for j in range(yoko):
rep1,rep2=input().split(",")
rep1=int(rep1)-1
rep2=int(rep2)-1
arr[rep1],arr[rep2] = arr[rep2],arr[rep1]
for k in range(tate):
print(arr[k])
|
[["-", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["-", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22], ["+", 0, 662, 12, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 662, 12, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 662, 12, 652, 3, 4, 0, 557, 0, 655], ["-", 36, 36, 0, 656, 0, 7, 8, 196, 0, 35]]
| 5
| 102
| 6
|
w=int(input())
l=[i+1 for i in range(w)]
n=int(input())
for _ in range(n):
a,b=[int(i)-1 for i in input().split(",")]
t=l[a]
l[a]=l[b]
l[b]=t
for i in w:
print(i)
|
w=int(input())
l=[i+1 for i in range(w)]
n=int(input())
for _ in range(n):
a,b=[int(i)-1 for i in input().split(",")]
t=l[a]
l[a]=l[b]
l[b]=t
for i in l:
print(i)
|
[["-", 36, 36, 36, 36, 0, 656, 0, 7, 12, 22], ["+", 36, 36, 36, 36, 0, 656, 0, 7, 12, 22]]
| 5
| 93
| 2
|
w = int(input())
n = int(input())
amida = []
for i in range(0,w+1):
amida.append(i)
for i in range(n):
ai,bi = map(int,input().split())
aa = amida[ai]
bb = amida[bi]
amida[ai] = bb
amida[bi] = aa
for i in range(1,w+1):
print(w[i])
|
w = int(input())
n = int(input())
amida = []
for i in range(0,w+1):
amida.append(i)
for i in range(n):
ai,bi = map(int,input().split(","))
aa = amida[ai]
bb = amida[bi]
amida[ai] = bb
amida[bi] = aa
for i in range(1,w+1):
print(amida[i])
|
[["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 655], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22]]
| 5
| 105
| 5
|
W = list(range(eval(input())+2))
for i in range(eval(input())):
a, b = list(map(int,input().split(",")))
W[a], W[b] = W[b], W[a]
for e in W[1:]:
print(e)
|
W=list(range(eval(input())+1))
for i in range(eval(input())):
a,b=list(map(int,input().split(",")))
W[a],W[b]=W[b],W[a]
for e in W[1:]:print(e)
|
[["-", 3, 4, 0, 652, 3, 4, 0, 657, 12, 612], ["+", 3, 4, 0, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 83
| 2
|
amida = []
def main():
num_vlines = int(input());
num_wlines = int(input());
init_amida(num_vlines)
count = 0;
while count < num_wlines :
ab = input().strip().split(',')
# print "--- input keys ---"
# pprint.pprint(ab)
transposition(int(ab[0]), int(ab[1]))
# print "--- dump amida ---"
# print amida.items()
count += 1
for i in range(1, num_vlines + 1):
print(amida[i], end=' ')
def init_amida(num_vlines):
for i in range(num_vlines + 1):
amida.append(i)
# pprint.pprint(amida)
def transposition(a, b):
tmp = amida[a]
amida[a] = amida[b]
amida[b] = tmp
main()
|
amida = []
def main():
num_vlines = int(input());
num_wlines = int(input());
init_amida(num_vlines)
count = 0;
while count < num_wlines :
ab = input().strip().split(',')
# print "--- input keys ---"
# pprint.pprint(ab)
transposition(int(ab[0]), int(ab[1]))
# print "--- dump amida ---"
# print amida.items()
count += 1
for i in range(1, num_vlines + 1):
print(amida[i])
def init_amida(num_vlines):
for i in range(num_vlines + 1):
amida.append(i)
# pprint.pprint(amida)
def transposition(a, b):
tmp = amida[a]
amida[a] = amida[b]
amida[b] = tmp
main()
|
[["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 21], ["-", 0, 1, 0, 652, 3, 4, 0, 653, 141, 22], ["-", 0, 1, 0, 652, 3, 4, 0, 653, 0, 32], ["-", 0, 652, 3, 4, 0, 653, 51, 557, 0, 654], ["-", 0, 652, 3, 4, 0, 653, 51, 557, 0, 6], ["-", 0, 652, 3, 4, 0, 653, 51, 557, 0, 655]]
| 5
| 161
| 6
|
w = int(input())
n = int(input())
s = [i+1 for i in range(w)]
for i in range(n):
a, b = list(map(int, input().split()))
tmp = s[a-1]
s[a-1] = s[b-1]
s[b-1] = tmp
for i in s:
print(i)
|
w = int(input())
n = int(input())
s = [i+1 for i in range(w)]
for i in range(n):
a, b = list(map(int, input().split(",")))
tmp = s[a-1]
s[a-1] = s[b-1]
s[b-1] = tmp
for i in s:
print(i)
|
[["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 655]]
| 5
| 95
| 3
|
import java.util.*;
public class Main {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
while (scan.hasNext()) {
double[] x = new double[3];
double[] y = new double[3];
for (int i = 0; i < 3; i++) {
x[i] = scan.nextDouble();
y[i] = scan.nextDouble();
}
double xp = scan.nextDouble();
double yp = scan.nextDouble();
for (int i = 0; i < 3; i++) {
x[i] = x[i] - xp;
y[i] = y[i] - yp;
}
double[] gaiseki = new double[3];
gaiseki[0] = x[0] * y[1] - y[0] * x[1];
gaiseki[1] = x[1] * y[2] - y[2] * x[1];
gaiseki[2] = x[2] * y[0] - y[2] * x[0];
int plus = 0;
int minus = 0;
for (int i = 0; i < 3; i++) {
if (gaiseki[i] > 0)
plus++;
if (gaiseki[i] < 0)
minus++;
}
String ans = "NO";
if (plus == 3 || minus == 3)
ans = "YES";
System.out.println(ans);
}
}
}
|
import java.util.*;
public class Main {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
while (scan.hasNext()) {
double[] x = new double[3];
double[] y = new double[3];
for (int i = 0; i < 3; i++) {
x[i] = scan.nextDouble();
y[i] = scan.nextDouble();
}
double xp = scan.nextDouble();
double yp = scan.nextDouble();
for (int i = 0; i < 3; i++) {
x[i] = x[i] - xp;
y[i] = y[i] - yp;
}
double[] gaiseki = new double[3];
gaiseki[0] = x[0] * y[1] - y[0] * x[1];
gaiseki[1] = x[1] * y[2] - y[1] * x[2];
gaiseki[2] = x[2] * y[0] - y[2] * x[0];
int plus = 0;
int minus = 0;
for (int i = 0; i < 3; i++) {
if (gaiseki[i] > 0)
plus++;
if (gaiseki[i] < 0)
minus++;
}
String ans = "NO";
if (plus == 3 || minus == 3)
ans = "YES";
System.out.println(ans);
}
}
}
|
[["-", 0, 11, 12, 16, 12, 16, 31, 504, 71, 499], ["+", 0, 11, 12, 16, 12, 16, 31, 504, 71, 499], ["-", 0, 11, 12, 16, 12, 16, 12, 504, 71, 499], ["+", 0, 11, 12, 16, 12, 16, 12, 504, 71, 499]]
| 3
| 334
| 4
|
q = [];
require("fs")
.readFileSync("/dev/stdin", "utf8")
.trim()
.split('\n')
.map(function(i) { i ? q.push(i) : console.log(q.pop()) })
|
q = [];
require("fs")
.readFileSync("/dev/stdin", "utf8")
.trim()
.split('\n')
.map(function(i) { +i ? q.push(i) : console.log(q.pop()) })
|
[["+", 8, 556, 0, 1, 0, 510, 15, 91, 17, 72]]
| 2
| 62
| 1
|
<?php
$stack = array();
$result = array();
while (!feof(STDIN)) {
$input = (int)rtrim(fgets(STDIN));
if (0 === $input) {
$result[] = array_pop($stack);
} else {
$stack[] = $input;
}
}
foreach ($result as $key => $value) {
printf("%d\n", $value);
}
|
<?php
$stack = array();
$result = array();
while (!feof(STDIN)) {
$input = rtrim(fgets(STDIN));
if ('0' === $input) {
$result[] = array_pop($stack);
} else {
$stack[] = $input;
}
}
foreach ($result as $key => $value) {
printf("%d\n", $value);
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 8, 9, 0, 1, 0, 11, 12, 74, 39, 615], ["-", 8, 9, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 0, 57, 15, 23, 0, 16, 31, 557, 0, 104]]
| 6
| 94
| 5
|
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
private Scanner sc;
private LinkedList<Integer> stack;
public static void main(String[] args) { new Main(); }
public Main() {
sc = new Scanner(System.in);
stack = new LinkedList<Integer>();
while (sc.hasNext() == true) {
int inst = Integer.parseInt(sc.next());
if (inst == 0) {
System.out.println(stack.pop());
} else {
stack.add(inst);
}
}
}
}
|
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
private Scanner sc;
private LinkedList<Integer> stack;
public static void main(String[] args) { new Main(); }
public Main() {
sc = new Scanner(System.in);
stack = new LinkedList<Integer>();
while (sc.hasNext() == true) {
int inst = Integer.parseInt(sc.next());
if (inst == 0) {
System.out.println(stack.pop());
} else {
stack.push(inst);
}
}
}
}
|
[["-", 0, 57, 75, 196, 0, 1, 0, 492, 141, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 492, 141, 22]]
| 3
| 130
| 2
|
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
Stack<Integer> s = new Stack<Integer>();
int y = cin.nextInt();
if (y == 0) {
return;
}
s.add(y);
while (!s.isEmpty()) {
int x = cin.nextInt();
if (x == 0) {
System.out.println(s.pop());
} else {
s.add(x);
}
}
}
}
|
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
Stack<Integer> s = new Stack<Integer>();
int y = cin.nextInt();
if (y == 0) {
return;
}
s.add(y);
while (cin.hasNext()) {
int x = cin.nextInt();
if (x == 0) {
System.out.println(s.pop());
} else {
s.add(x);
}
}
}
}
|
[["-", 8, 196, 0, 52, 15, 15, 0, 91, 17, 111], ["-", 0, 52, 15, 15, 0, 91, 439, 492, 500, 22], ["+", 8, 196, 0, 52, 15, 15, 0, 492, 500, 22], ["-", 0, 52, 15, 15, 0, 91, 439, 492, 141, 22], ["+", 8, 196, 0, 52, 15, 15, 0, 492, 141, 22]]
| 3
| 133
| 5
|
#include <stdio.h>
int main(int argc, const char *argv[]) {
int a[10], i;
int n = 0;
while (scanf("%d", &i) != EOF) {
if (i != 0) {
a[n++] = i;
} else {
printf("%d", a[--n]);
}
}
return 0;
}
|
#include <stdio.h>
int main(int argc, const char *argv[]) {
int a[10];
int i, n = 0;
while (scanf("%d", &i) != EOF) {
if (i != 0) {
a[n++] = i;
} else {
printf("%d\n", a[--n]);
}
}
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 81
| 5
|
#include <stdio.h>
int pop();
void push(int x);
int stack[11];
int stack_top = 0;
int main(void) {
int n, num;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
num = pop();
printf("%d", num);
} else {
push(n);
}
}
return 0;
}
int pop() {
stack_top--;
return stack[stack_top];
}
void push(int x) {
stack[stack_top] = x;
stack_top++;
return;
}
|
#include <stdio.h>
int pop();
void push(int x);
int stack[11];
int stack_top = 0;
int main(void) {
int n, num;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
num = pop();
printf("%d\n", num);
} else {
push(n);
}
}
return 0;
}
int pop() {
stack_top--;
return stack[stack_top];
}
void push(int x) {
stack[stack_top] = x;
stack_top++;
return;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 122
| 1
|
#include <stdio.h>
int main() {
int x = 0, i, n, data[100];
while (scanf("%d", &x) != EOF) {
if (x == 0) {
printf("%d", data[i]);
i--;
} else {
i++;
data[i] = x;
}
}
return 0;
}
|
#include <stdio.h>
int main() {
int x = 0, i, n, data[100];
while (scanf("%d", &x) != EOF) {
if (x == 0) {
printf("%d\n", data[i]);
i--;
} else {
i++;
data[i] = x;
}
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 77
| 1
|
#include <stdio.h>
int main() {
int v[1000], n, i = 0;
while (scanf("%d", &n) != EOF) {
if (n = 0)
printf("%d\n", v[--i]);
else
v[i++] = n;
}
return 0;
}
|
#include <stdio.h>
int main() {
int v[1000], n, i = 0;
while (scanf("%d", &n) != EOF) {
if (n == 0)
printf("%d\n", v[--i]);
else
v[i++] = n;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60]]
| 0
| 68
| 2
|
#include <math.h>
#include <stdio.h>
int main() {
int n, sya[1000], cnt;
cnt = 0;
while (scanf("%d", &n) == 0) {
if (n == 0) {
cnt = cnt - 1;
printf("%d\n", sya[cnt]);
} else {
// scanf("%d",&n);
sya[cnt] = n;
cnt = cnt + 1;
}
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int n, sya[1000], cnt;
cnt = 0;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
cnt = cnt - 1;
printf("%d\n", sya[cnt]);
} else {
sya[cnt] = n;
cnt = cnt + 1;
}
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 60], ["-", 8, 9, 0, 52, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 79], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 12, 22]]
| 0
| 87
| 4
|
#include <stdio.h>
int main() {
int stack[101] = {0};
int n;
int i = 0;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
i--;
printf("%d", stack[i]);
}
else {
stack[i] = n;
i++;
}
}
return 0;
}
|
#include <stdio.h>
int main() {
int stack[101] = {0};
int n;
int i = 0;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
i--;
printf("%d\n", stack[i]);
}
else {
stack[i] = n;
i++;
}
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 81
| 1
|
#include <stdio.h>
int data[10] = {0}, data2[10] = {0}, i = 0, j = 0;
void push(int n) { data[i] = n; }
void pop(int n) {
data2[j] = data[i];
j++;
data[i + 1] = 0;
}
int main() {
int n, k;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
i--;
pop(n);
} else {
push(n);
i++;
}
}
for (k = 0; k <= j; k++) {
printf("%d\n", data2[k]);
}
}
|
#include <stdio.h>
int data[10] = {0}, data2[100] = {0}, i = 0, j = 0;
void push(int n) { data[i] = n; }
void pop(int n) {
data2[j] = data[i];
j++;
data[i + 1] = 0;
}
int main() {
int n, k;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
i--;
pop(n);
} else {
push(n);
i++;
}
}
for (k = 0; k < j; k++) {
printf("%d\n", data2[k]);
}
}
|
[["-", 0, 30, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 0, 30, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18]]
| 0
| 156
| 4
|
n, *a = &n;
main() {
for (; ~scanf("%s", a);)
*a % 8 ? a++ : puts(--a);
}
|
n, *a = &n;
main() {
for (; ~scanf("%s", a);)
*a % 12 ? a++ : puts(--a);
}
|
[["-", 0, 7, 8, 1, 0, 41, 15, 16, 12, 13], ["+", 0, 7, 8, 1, 0, 41, 15, 16, 12, 13]]
| 0
| 42
| 2
|
main() {
int i = 0, t[100], w;
while (scanf("%d", &w) != -1) {
if (w == 0)
printf("%d", t[--i]);
else
t[i++] = w;
}
return 0;
}
|
main() {
int i = 0, t[100], w;
while (scanf("%d", &w) != -1) {
if (w == 0)
printf("%d\n", t[--i]);
else
t[i++] = w;
}
return 0;
}
|
[["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 64
| 1
|
// AOJ Volume 0 Problem 0012
#include <stdio.h>
int main(void) {
int cars[1000];
int n;
int car_no;
n = 0;
while (scanf("%d", &car_no) != EOF) {
if (car_no == 0) {
printf("[%d]\n", cars[--n]);
} else {
cars[n++] = car_no;
}
}
return (0);
}
|
// AOJ Volume 0 Problem 0012
#include <stdio.h>
int main(void) {
int cars[1000];
int n;
int car_no;
n = 0;
while (scanf("%d", &car_no) != EOF) {
if (car_no == 0) {
printf("%d\n", cars[--n]);
} else {
cars[n++] = car_no;
}
}
return (0);
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 80
| 2
|
#include <stdio.h>
int main(void) {
int in[10];
int i;
int n;
for (i = 0; i < 10; i++) {
in[i] = 0;
}
while (scanf("%d", &n) != 1) {
if (n != 0) {
for (i = 0; i < 10; i++) {
if (in[i] == 0) {
in[i] = n;
break;
}
}
} else {
for (i = 9; i >= 0; i--) {
if (in[i] != 0) {
printf("%d\n", in[i]);
in[i] = 0;
break;
}
}
}
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int in[10];
int i;
int n;
for (i = 0; i < 10; i++) {
in[i] = 0;
}
while (scanf("%d", &n) == 1) {
if (n != 0) {
for (i = 0; i < 10; i++) {
if (in[i] == 0) {
in[i] = n;
break;
}
}
} else {
for (i = 9; i >= 0; i--) {
if (in[i] != 0) {
printf("%d\n", in[i]);
in[i] = 0;
break;
}
}
}
}
return (0);
}
|
[["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 79], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 60]]
| 0
| 158
| 2
|
#include <stdio.h>
int main(void) {
int Cars[10];
int i = 0;
int Temp;
while (scanf("%d", &Temp) == 1) {
if (Temp == 0) {
i--;
printf("%d\n", Cars[Temp]);
} else {
Cars[i] = Temp;
i++;
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int Cars[10];
int i = 0;
int Temp;
while (scanf("%d", &Temp) == 1) {
if (Temp == 0) {
i--;
printf("%d\n", Cars[i]);
} else {
Cars[i] = Temp;
i++;
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 69, 71, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 71, 22]]
| 0
| 79
| 2
|
#include <stdio.h>
int main(void) {
int stack[11] = {0}, buf, crpos = 0;
while (scanf("%d", &buf) != EOF) {
if (buf == 0) {
crpos--;
printf("___%d\n", stack[crpos]);
} else {
stack[crpos] = buf;
crpos++;
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int stack[10] = {0}, buf, crpos = 0;
while (scanf("%d", &buf) != EOF) {
if (buf == 0) {
crpos--;
printf("%d\n", stack[crpos]);
} else {
stack[crpos] = buf;
crpos++;
}
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 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
| 81
| 4
|
#include <stdio.h>
int main(void) {
int stack[10] = {0}, buf, crpos = 0;
while (scanf("%d", &buf) != EOF) {
if (buf == 0) {
printf("%d\n", stack[crpos--]);
} else {
stack[crpos++] = buf;
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int stack[10] = {0}, buf, crpos = 0;
while (scanf("%d", &buf) != EOF) {
if (buf == 0) {
printf("%d\n", stack[--crpos]);
} else {
stack[crpos++] = buf;
}
}
return 0;
}
|
[["-", 0, 2, 3, 4, 0, 69, 71, 27, 28, 22], ["+", 0, 2, 3, 4, 0, 69, 71, 27, 28, 22]]
| 0
| 77
| 2
|
s[11];
main(t, p) {
for (; *s = ~scanf("%d", &t); t ? s[p++] = t : printf("%d\n", s[--p]))
;
}
|
s[9];
main(p, t) {
for (; *s = ~scanf("%d", &t); t ? s[p++] = t : printf("%d\n", s[--p]))
;
}
|
[["-", 36, 36, 0, 30, 0, 1, 0, 69, 71, 13], ["+", 36, 36, 0, 30, 0, 1, 0, 69, 71, 13], ["-", 0, 30, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 0, 30, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 0, 30, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 0, 30, 0, 1, 0, 2, 3, 4, 0, 22]]
| 0
| 56
| 6
|
#include <stdio.h>
int main(void) {
int j, i, l[1000], a[1000], b;
for (i = 0;; i++) {
if (scanf("%d", &a[i]) == EOF)
break;
else if (a[i] == 0) {
printf("a%d\n", a[i - 1]);
i--;
i--;
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int j, i, l[1000], a[1000], b;
for (i = 0;; i++) {
if (scanf("%d", &a[i]) == EOF)
break;
else if (a[i] == 0) {
printf("%d\n", a[i - 1]);
i--;
i--;
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 93
| 2
|
#include <stdio.h>
int stack[1000], point = 0;
int fstack(int com, int num) {
int data;
if (com == 0) {
data = stack[point];
stack[point] = num;
point--;
return data;
}
if (com == 1) {
point++;
stack[point] = num;
return 0;
} else {
return -1;
}
}
int main() {
int a;
while (!scanf("%d", &a)) {
if (a == 0) {
a = fstack(0, 0);
printf("%d", a);
} else {
fstack(1, a);
}
}
return 0;
}
|
#include <stdio.h>
int stack[1000], point = 0;
int fstack(int com, int num) {
int data;
if (com == 0) {
data = stack[point];
stack[point] = num;
point--;
return data;
}
if (com == 1) {
point++;
stack[point] = num;
return 0;
} else {
return -1;
}
}
int main() {
int a;
while (scanf("%d", &a) != EOF) {
if (a == 0) {
a = fstack(0, 0);
printf("%d\n", a);
} else {
fstack(1, a);
}
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 23, 0, 91, 17, 111], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 79], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 144
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#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 pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double ESP = 1e-10;
using namespace std;
int main() {
int in;
queue<int> out;
while (cin >> in) {
if (in)
out.push(in);
else {
cout << out.front() << endl;
out.pop();
}
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#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 pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double ESP = 1e-10;
using namespace std;
int main() {
int in;
stack<int> out;
while (cin >> in) {
if (in)
out.push(in);
else {
cout << out.top() << endl;
out.pop();
}
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["-", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["-", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["+", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["-", 0, 16, 31, 16, 12, 2, 63, 118, 119, 120], ["+", 0, 16, 31, 16, 12, 2, 63, 118, 119, 120]]
| 1
| 125
| 8
|
#include <stdio.h>
#include <string.h>
#include <stack>
#include <iostream>
using namespace std;
int main() {
int input;
stack<int> train;
while (scanf("%d", &input) != EOF) {
// scanf("%d",&input);
if (input != 0)
train.push(input);
else {
printf("%d", train.top());
train.pop();
}
}
}
// if(strcmp(c,pu) == 0){
//
// scanf("%s",&color);
//
// st.push(color);
//
// }
//
// if(strcmp(c,po) == 0){
//
// cout<<st.top()<<endl;
//
// st.pop();
//
// }
//
// if(strcmp(c,qu) == 0){
//
// return 0;
//
// }
//
// }
//}
|
#include <stdio.h>
#include <string.h>
#include <stack>
#include <iostream>
using namespace std;
int main() {
int input;
stack<int> train;
while (scanf("%d", &input) != EOF) {
// scanf("%d",&input);
if (input != 0)
train.push(input);
else {
printf("%d\n", train.top());
train.pop();
}
}
}
// if(strcmp(c,pu) == 0){
//
// scanf("%s",&color);
//
// st.push(color);
//
// }
//
// if(strcmp(c,po) == 0){
//
// cout<<st.top()<<endl;
//
// st.pop();
//
// }
//
// if(strcmp(c,qu) == 0){
//
// return 0;
//
// }
//
// }
//}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 103
| 7
|
#include <iostream>
#include <malloc.h>
using namespace std;
struct stack {
int element;
struct stack *next;
};
int top(struct stack *s) { return s->element; }
struct stack *pop(struct stack *s) {
struct stack *p, *q;
q = s;
p = s->next;
free(q);
s = p;
return s;
}
struct stack *push(struct stack *s, int x) {
struct stack *p, *q;
q = s;
p = (struct stack *)malloc(sizeof(struct stack));
p->element = x;
p->next = q;
s = p;
return s;
}
int main() {
struct stack *S = NULL;
int num;
while (1) {
cin >> num;
if (num == 0) {
cout << top(S) << endl;
S = pop(S);
} else {
S = push(S, num);
}
}
return 0;
}
|
#include <iostream>
#include <malloc.h>
using namespace std;
struct stack {
int element;
struct stack *next;
};
int top(struct stack *s) { return s->element; }
struct stack *pop(struct stack *s) {
struct stack *p, *q;
q = s;
p = s->next;
free(q);
s = p;
return s;
}
struct stack *push(struct stack *s, int x) {
struct stack *p, *q;
q = s;
p = (struct stack *)malloc(sizeof(struct stack));
p->element = x;
p->next = q;
s = p;
return s;
}
int main() {
struct stack *S = NULL;
int num;
while (cin >> num) {
if (num == 0) {
cout << top(S) << endl;
S = pop(S);
} else {
S = push(S, num);
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 52, 15, 339, 51, 13], ["-", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45]]
| 1
| 205
| 6
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
stack<int> s;
s.push(n);
int a;
cin >> a;
if (a == 0) {
cout << s.top() << endl;
s.pop();
} else {
s.push(a);
}
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
stack<int> s;
s.push(n);
int a;
while (cin >> a) {
if (a == 0) {
cout << s.top() << endl;
s.pop();
} else {
s.push(a);
}
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 92
| 6
|
// 0013
#include <bits/stdc++.h>
using namespace std;
int main() {
int tmp, i = 0, j, k = 0, f[11];
vector<int> ans;
while (cin >> tmp) {
if (tmp == 0) {
ans[k] = f[i - 1];
f[i - 1] = '\0';
i--;
k++;
} else {
f[i] = tmp;
i++;
}
}
for (j = 0; j < k; j++) {
cout << ans[j] << endl;
}
return 0;
}
|
// 0013
#include <bits/stdc++.h>
using namespace std;
int main() {
int tmp, i = 0, j, k = 0, f[11];
vector<int> ans;
while (cin >> tmp) {
if (tmp == 0) {
ans.push_back(f[i - 1]);
f[i - 1] = '\0';
i--;
k++;
} else {
f[i] = tmp;
i++;
}
}
for (j = 0; j < k; j++) {
cout << ans[j] << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 70], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 73], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 64, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 64, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 25]]
| 1
| 122
| 8
|
#include <iostream>
#include <stack>
int main() {
std::stack<int> rail;
int buf;
// repeat until "cin" fails.
while (std::cin >> buf) {
if (buf == 0) { // train goes out.
std::cout << rail.top();
rail.pop();
} else { // train comes in.
rail.push(buf);
}
}
return 0;
}
|
#include <iostream>
#include <stack>
int main() {
std::stack<int> rail;
int buf;
// repeat until "cin" fails.
while (std::cin >> buf) {
if (buf == 0) { // train goes out.
std::cout << rail.top() << std::endl;
rail.pop();
} else { // train comes in.
rail.push(buf);
}
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 64, 9, 0, 1, 0, 16, 12, 343, 345, 348], ["+", 64, 9, 0, 1, 0, 16, 12, 343, 0, 349], ["+", 64, 9, 0, 1, 0, 16, 12, 343, 141, 22]]
| 1
| 71
| 4
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> a;
int n;
while (cin >> n) {
if (n == 0) {
cout << a.back();
a.pop_back(); // delete
} else
a.push_back(n);
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> a;
int n;
while (cin >> n) {
if (n == 0) {
cout << a.back() << endl;
a.pop_back(); // delete
} else
a.push_back(n);
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 65
| 2
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int a[10], i = 0, n;
while (scanf("%d", n) == 1) {
if (n != 0) {
a[i] = n;
i++;
} else {
i--;
cout << a[i] << endl;
}
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int a[10], i = 0, n;
while (scanf("%d", &n) == 1) {
if (n != 0) {
a[i] = n;
i++;
} else {
i--;
cout << a[i] << endl;
}
}
return 0;
}
|
[["+", 51, 16, 31, 2, 3, 4, 0, 66, 17, 67]]
| 1
| 77
| 1
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int n;
stack<int> s;
while (true) {
cin >> n;
if (n == 0) {
cout << s.top() << endl;
s.pop();
} else {
s.push(n);
}
}
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int n;
stack<int> s;
while (cin >> n) {
if (n == 0) {
cout << s.top() << endl;
s.pop();
} else {
s.push(n);
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 52, 15, 339, 51, 146], ["-", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45]]
| 1
| 70
| 6
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> v;
vector<int>::iterator pv = v.begin();
int n;
while (cin >> n) {
if (n == 0) {
int x = v.size();
cout << v[x - 1] << endl;
v.pop_back();
}
v.push_back(n);
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> v;
vector<int>::iterator pv = v.begin();
int n;
while (cin >> n) {
if (n == 0) {
int x = v.size();
cout << v[x - 1] << endl;
v.pop_back();
continue;
}
v.push_back(n);
}
return 0;
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 117], ["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 35]]
| 1
| 89
| 2
|
#include "bits/stdc++.h"
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
stack<int> st;
int x;
while (cin >> x) {
if (x == 0) {
cout << st.top();
st.pop();
} else
st.push(x);
}
}
|
#include "bits/stdc++.h"
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
stack<int> st;
int x;
while (cin >> x) {
if (x == 0) {
cout << st.top() << endl;
st.pop();
} else
st.push(x);
}
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 75
| 2
|
/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES
#include <algorithm> // max??¢??°??????
#include <cmath> // ??°??????
#include <fstream> // ??????????????\??????
#include <iomanip> // stream???????????¢???
#include <iostream> // ?¨??????\??????
#include <string> // ???????????¢???
#include <vector> // ???????????????
using std::cin;
using std::cout;
using std::endl;
using std::fixed; // ???????????????????¨???????????????????????????????
using std::
setprecision; // ?????°????°???°?????\???????????°????????????????????¨????????\???
using std::string;
using std::vector; // ????´???°????????????????????????
int main() {
int num;
vector<int> stack;
while (cin >> num) {
if (num == 0) {
// ??????????????????????????????????¶????
cout << stack.back();
stack.pop_back();
continue;
}
// ???????????????????????°????????\??????
stack.push_back(num);
}
return 0;
}
|
/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES
#include <algorithm> // max??¢??°??????
#include <cmath> // ??°??????
#include <fstream> // ??????????????\??????
#include <iomanip> // stream???????????¢???
#include <iostream> // ?¨??????\??????
#include <string> // ???????????¢???
#include <vector> // ???????????????
using std::cin;
using std::cout;
using std::endl;
using std::fixed; // ???????????????????¨???????????????????????????????
using std::
setprecision; // ?????°????°???°?????\???????????°????????????????????¨????????\???
using std::string;
using std::vector; // ????´???°????????????????????????
int main() {
int num;
vector<int> stack;
while (cin >> num) {
if (num == 0) {
// ??????????????????????????????????¶????
cout << stack.back() << endl;
stack.pop_back();
continue;
}
// ???????????????????????°????????\??????
stack.push_back(num);
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 121
| 2
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> st;
int a;
while (cin >> a) {
if (a == 0) {
cout << st.top() << endl;
st.pop();
}
st.push(a);
}
return 0;
}
|
//
// main.cpp
// BT
//
// Created by h3037175 on 2017/07/27.
// Copyright ?? 2017??´ h3037175. All rights reserved.
//
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> st;
int a;
while (cin >> a) {
if (a == 0) {
cout << st.top() << endl;
st.pop();
} else {
st.push(a);
}
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 65
| 3
|
#include <bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(), vec.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll INF = 1000000010;
const ll LINF = 4000000000000000010LL;
const int MAX = 310;
const double EPS = 1e-6;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int n;
queue<int> q;
while (cin >> n) {
if (n == 0) {
cout << q.front() << endl;
q.pop();
} else {
q.push(n);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(), vec.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll INF = 1000000010;
const ll LINF = 4000000000000000010LL;
const int MAX = 310;
const double EPS = 1e-6;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int n;
stack<int> q;
while (cin >> n) {
if (n == 0) {
cout << q.top() << endl;
q.pop();
} else {
q.push(n);
}
}
}
|
[["-", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["+", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["-", 0, 16, 31, 16, 12, 2, 63, 118, 119, 120], ["+", 0, 16, 31, 16, 12, 2, 63, 118, 119, 120]]
| 1
| 146
| 4
|
#include <iostream>
#include <utility>
using namespace std;
int main() {
int a[100];
int i = 0;
while (1) {
cin >> a[i];
if (a[i] == 0) {
int j = i;
while (1) {
j--;
if (a[j] != 0) {
cout << a[j] << endl;
a[j] = 0;
break;
}
}
}
i++;
}
return 0;
}
|
#include <iostream>
#include <utility>
using namespace std;
int main() {
int a[100];
int i = 0;
while (cin >> a[i]) {
if (a[i] == 0) {
int j = i;
while (1) {
j--;
if (a[j] != 0) {
cout << a[j] << endl;
a[j] = 0;
break;
}
}
}
i++;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 52, 15, 339, 51, 13], ["-", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45]]
| 1
| 98
| 6
|
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
int num;
stack<int> st;
while (1) {
cin >> num;
st.push(num);
if (num == 0) {
st.pop(); // 0ツづーツ渉慊つュ
cout << st.top() << endl;
st.pop();
}
}
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
int num;
stack<int> st;
while (cin >> num) {
st.push(num);
if (num == 0) {
st.pop(); // 0ツづーツ渉慊つュ
cout << st.top() << endl;
st.pop();
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 52, 15, 339, 51, 13], ["-", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45]]
| 1
| 75
| 6
|
/*
This figure shows railway tracks for reshuffling cars. The rail tracks end in
the bottom and the top-left rail track is used for the entrace and the top-right
rail track is used for the exit. Ten cars, which have numbers from 1 to 10
respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
An entry of a car is represented by its number.
An exit of a car is represented by 0
For example, a sequence
1 6 0 8 10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6
exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are
represented by the sequence of car numbers. The program should read the sequence
of car numbers and 0, and print numbers of cars which exit from the rail tracks
in order. At the first, there are no cars on the rail tracks. You can assume
that 0 will not be given when there is no car on the rail tracks.
*/
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> cars(100000), ans;
int temp, i = 0, m;
while (cin >> temp) {
if (temp != 0) {
cars[i] = temp;
i++;
} else {
int p = i - 1;
if (p < 0) {
ans.push_back(cars[p]);
i--;
}
}
}
for (int j = 0; j < ans.size(); j++)
cout << ans[j] << endl;
return 0;
}
|
/*
This figure shows railway tracks for reshuffling cars. The rail tracks end in
the bottom and the top-left rail track is used for the entrace and the top-right
rail track is used for the exit. Ten cars, which have numbers from 1 to 10
respectively, use the rail tracks.
We can simulate the movement (comings and goings) of the cars as follow:
An entry of a car is represented by its number.
An exit of a car is represented by 0
For example, a sequence
1 6 0 8 10
demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6
exits from the rail tracks, and then car 8 and car 10 enter.
Write a program which simulates comings and goings of the cars which are
represented by the sequence of car numbers. The program should read the sequence
of car numbers and 0, and print numbers of cars which exit from the rail tracks
in order. At the first, there are no cars on the rail tracks. You can assume
that 0 will not be given when there is no car on the rail tracks.
*/
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> cars(100000), ans;
int temp, i = 0, m;
while (cin >> temp) {
if (temp != 0) {
cars[i] = temp;
i++;
} else {
int p = i - 1;
if (p >= 0) {
ans.push_back(cars[p]);
i--;
}
}
}
for (int j = 0; j < ans.size(); j++)
cout << ans[j] << endl;
return 0;
}
|
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 124
| 2
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int n, count = 0;
stack<int> get;
while (1) {
cin >> n;
if (n == 0) {
cout << get.top() << endl;
get.pop();
count -= 1;
} else {
get.push(n);
count += 1;
}
}
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int n, count = 0;
stack<int> get;
while (cin >> n) {
if (n == 0) {
cout << get.top() << endl;
get.pop();
count -= 1;
} else {
get.push(n);
count += 1;
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 52, 15, 339, 51, 13], ["-", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45]]
| 1
| 82
| 6
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> train;
int n;
while (cin >> n) {
if (n != 0) {
train.push_back(n);
} else {
cout << train.back();
train.pop_back();
}
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> train;
int n;
while (cin >> n) {
if (n != 0) {
train.push_back(n);
} else {
cout << train.back() << endl;
;
train.pop_back();
}
}
return 0;
}
|
[["+", 75, 76, 0, 9, 0, 1, 0, 16, 17, 151], ["+", 75, 76, 0, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 57, 75, 76, 0, 9, 0, 1, 0, 35]]
| 1
| 66
| 3
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int n;
stack<int> S;
while (cin >> n) {
if (n == 0) {
cout << S.top();
S.pop();
} else {
S.push(n);
}
}
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int n;
stack<int> S;
while (cin >> n) {
if (n == 0) {
cout << S.top() << endl;
S.pop();
} else {
S.push(n);
}
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 66
| 2
|
#include <cstdio>
#include <queue>
using namespace std;
int main() {
int x;
queue<int> q;
while (scanf("%d", &x) != EOF) {
if (x == 0) {
printf("%d\n", q.front());
q.pop();
} else {
q.push(x);
}
}
return 0;
}
|
#include <cstdio>
#include <stack>
using namespace std;
int main() {
int x;
stack<int> q;
while (scanf("%d", &x) != EOF) {
if (x == 0) {
printf("%d\n", q.top());
q.pop();
} else {
q.push(x);
}
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["-", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["+", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["-", 0, 2, 3, 4, 0, 2, 63, 118, 119, 120], ["+", 0, 2, 3, 4, 0, 2, 63, 118, 119, 120]]
| 1
| 80
| 6
|
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
stack<int> s;
int buf;
while (1) {
cin >> buf;
if (buf == 0) {
cout << s.top() << endl;
s.pop();
} else {
s.push(buf);
}
}
}
|
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
stack<int> s;
int buf;
while (cin >> buf) {
if (buf == 0) {
cout << s.top() << endl;
s.pop();
} else {
s.push(buf);
}
}
}
|
[["-", 0, 14, 8, 9, 0, 52, 15, 339, 51, 13], ["-", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45]]
| 1
| 68
| 6
|
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
double n;
stack<double> buf;
while (true) {
cin >> n;
if (cin.eof())
break;
if (n != 0)
buf.push(n);
else {
cout << buf.top();
buf.pop();
}
}
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
double n;
stack<double> buf;
while (true) {
cin >> n;
if (cin.eof())
break;
if (n != 0)
buf.push(n);
else {
cout << buf.top() << endl;
buf.pop();
}
}
return 0;
}
|
[["+", 75, 76, 0, 9, 0, 1, 0, 16, 17, 151], ["+", 75, 76, 0, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 77
| 2
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int train;
stack<int> out;
while (cin >> train) {
if (train != 0) {
out.push(train);
} else {
cout << out.top() << " ";
out.pop();
}
}
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int train;
stack<int> out;
while (cin >> train) {
if (train != 0) {
out.push(train);
} else {
cout << out.top() << endl;
out.pop();
}
}
return 0;
}
|
[["-", 0, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["-", 0, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 75, 76, 0, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 70
| 4
|
#include <iostream>
using namespace std;
int main() {
int k = 0, b;
int a[1];
while (cin >> b) {
if (b != 0) {
a[k] = b;
k = k + 1;
}
if (b == 0) {
cout << a[k - 1] << endl;
k = k - 1;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int k = 0, b;
int a[1000000];
while (cin >> b) {
if (b != 0) {
a[k] = b;
k = k + 1;
}
if (b == 0) {
cout << a[k - 1] << endl;
k = k - 1;
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
| 1
| 82
| 2
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int a;
stack<int> syaryo;
while (cin >> a) {
cin >> a;
if (a != 0) {
syaryo.push(a);
}
else {
cout << syaryo.top() << endl;
syaryo.pop();
}
}
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int a;
stack<int> syaryo;
while (cin >> a) {
if (a != 0) {
syaryo.push(a);
}
else {
cout << syaryo.top() << endl;
syaryo.pop();
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 152], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 72
| 4
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<char> stk;
char c;
while (cin >> c) {
if (c == '0') {
cout << stk.top() << endl;
stk.pop();
} else {
stk.push(c);
}
}
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> stk;
int c;
while (cin >> c) {
if (c == 0) {
cout << stk.top() << endl;
stk.pop();
} else {
stk.push(c);
}
}
return 0;
}
|
[["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 57, 15, 339, 51, 16, 12, 103, 0, 104]]
| 1
| 70
| 6
|
car = []
while input = gets
input = input.to_i
if input.zero? then puts(car.shift)
else
car.push input
end
end
|
car = []
while input = gets
input = input.to_i
if input.zero? then puts(car.pop)
else
car.push input
end
end
|
[["-", 64, 749, 0, 652, 3, 4, 0, 652, 735, 22], ["+", 64, 749, 0, 652, 3, 4, 0, 652, 735, 22]]
| 4
| 31
| 2
|
arr = []
while line = gets
num = line.to_i
if num.zero?
putsarr.pop
else
arr << num
end
end
|
arr = []
while line = gets
num = line.to_i
if num.zero?
puts arr.pop
else
arr << num
end
end
|
[["-", 8, 170, 0, 121, 64, 749, 0, 652, 486, 22], ["+", 8, 170, 0, 121, 64, 749, 0, 652, 735, 22], ["+", 64, 749, 0, 652, 3, 4, 0, 652, 486, 22]]
| 4
| 26
| 3
|
import sys
cars = []
for line in sys.stdin:
car = int(line)
if car:
cars.append(num)
else:
print(cars.pop())
|
import sys
cars = []
for line in sys.stdin:
car = int(line)
if car:
cars.append(car)
else:
print(cars.pop())
|
[["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
| 5
| 38
| 2
|
import java.util.Scanner;
class Main {
public static double[][] solEq(double[][] a) {
int n = a.length, m = a[0].length;
for (int ipv = 0; ipv < n; ipv++) {
double max = 0.0;
int row = 0;
for (int i = ipv; i < n; i++) {
if (Math.abs(a[i][ipv]) > max) {
max = a[i][ipv];
row = i;
}
}
if (max == 0.0) {
break;
}
if (ipv != row) {
for (int j = 0; j < m; j++) {
double temp = a[ipv][j];
a[ipv][j] = a[row][j];
a[row][j] = temp;
}
}
double inv_pv = 1.0 / a[ipv][ipv];
for (int j = 0; j < m; j++) {
a[ipv][j] *= inv_pv;
}
for (int i = 0; i < n; i++) {
if (i != ipv) {
double temp = a[i][ipv];
for (int j = 0; j < m; j++) {
a[i][j] -= temp * a[ipv][j];
}
}
}
}
return a;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
double[][] point = new double[4][2];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 2; j++) {
point[i][j] = sc.nextDouble();
}
}
double[][] mat = {{point[1][0] - point[0][0], point[2][0] - point[0][0],
point[3][0] - point[0][0]},
{point[1][1] - point[0][1], point[2][1] - point[0][1],
point[3][1] - point[0][1]}};
mat = solEq(mat);
if (mat[0][2] >= 0 && mat[1][2] >= 0 && mat[0][2] + mat[0][2] <= 1) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
|
import java.util.Scanner;
class Main {
public static double[][] solEq(double[][] a) {
int n = a.length, m = a[0].length;
for (int ipv = 0; ipv < n; ipv++) {
double max = 0.0;
int row = 0;
for (int i = ipv; i < n; i++) {
if (Math.abs(a[i][ipv]) > max) {
max = a[i][ipv];
row = i;
}
}
if (max == 0.0) {
break;
}
if (ipv != row) {
for (int j = 0; j < m; j++) {
double temp = a[ipv][j];
a[ipv][j] = a[row][j];
a[row][j] = temp;
}
}
double inv_pv = 1.0 / a[ipv][ipv];
for (int j = 0; j < m; j++) {
a[ipv][j] *= inv_pv;
}
for (int i = 0; i < n; i++) {
if (i != ipv) {
double temp = a[i][ipv];
for (int j = 0; j < m; j++) {
a[i][j] -= temp * a[ipv][j];
}
}
}
}
return a;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
double[][] point = new double[4][2];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 2; j++) {
point[i][j] = sc.nextDouble();
}
}
double[][] mat = {{point[1][0] - point[0][0], point[2][0] - point[0][0],
point[3][0] - point[0][0]},
{point[1][1] - point[0][1], point[2][1] - point[0][1],
point[3][1] - point[0][1]}};
mat = solEq(mat);
if (mat[0][2] > 0 && mat[1][2] > 0 && mat[0][2] + mat[1][2] <= 1) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
|
[["-", 15, 15, 0, 16, 31, 16, 31, 16, 17, 20], ["+", 15, 15, 0, 16, 31, 16, 31, 16, 17, 47], ["-", 15, 15, 0, 16, 31, 16, 12, 16, 17, 20], ["+", 15, 15, 0, 16, 31, 16, 12, 16, 17, 47], ["-", 12, 16, 31, 16, 12, 504, 516, 504, 71, 499], ["+", 12, 16, 31, 16, 12, 504, 516, 504, 71, 499]]
| 3
| 580
| 6
|
import java.util.Scanner;
public class Main {
Scanner sc;
boolean solve(double[][] point) {
double[][] v = new double[3][2];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 2; ++j) {
v[i][j] = point[i][j] - point[3][j];
}
}
double theta = 0;
for (int i = 0; i < 3; ++i) {
double ip = (v[i][0] * v[(i + 1) % 3][0] + v[i][1] * v[(i + 1) % 3][1]);
theta += Math.acos(ip / Math.hypot(v[i][0], v[i][1]) /
Math.hypot(v[(i + 1) % 3][0], v[(i + 1) % 3][1]));
}
return theta >= Math.PI * 2;
}
double nd() { return sc.nextDouble(); }
void io() {
sc = new Scanner(System.in);
double[][] point = new double[4][2];
while (sc.hasNext()) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 2; ++j) {
point[i][j] = nd();
}
}
System.out.println(solve(point) ? "YES" : "NO");
}
}
public static void main(String[] args) { new Main().io(); }
}
|
import java.util.Scanner;
public class Main {
Scanner sc;
boolean solve(double[][] point) {
double[][] v = new double[3][2];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 2; ++j) {
v[i][j] = point[i][j] - point[3][j];
}
}
double theta = 0;
for (int i = 0; i < 3; ++i) {
double ip = (v[i][0] * v[(i + 1) % 3][0] + v[i][1] * v[(i + 1) % 3][1]);
theta += Math.acos(ip / Math.hypot(v[i][0], v[i][1]) /
Math.hypot(v[(i + 1) % 3][0], v[(i + 1) % 3][1]));
}
return theta >= Math.PI * 2 - 1e-7;
}
double nd() { return sc.nextDouble(); }
void io() {
sc = new Scanner(System.in);
double[][] point = new double[4][2];
while (sc.hasNext()) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 2; ++j) {
point[i][j] = nd();
}
}
System.out.println(solve(point) ? "YES" : "NO");
}
}
public static void main(String[] args) { new Main().io(); }
}
|
[["+", 8, 196, 0, 37, 0, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 37, 0, 16, 12, 16, 12, 515]]
| 3
| 381
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.