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
a = input() print(a.upper)
a = input() print(a.upper())
[["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
11
s = input().lower() print(s)
s = input().upper() print(s)
[["-", 0, 1, 0, 662, 12, 652, 63, 319, 319, 22], ["+", 0, 1, 0, 662, 12, 652, 63, 319, 319, 22]]
5
13
import java.util.Scanner; public class Main { public static boolean solve(double[][] x) { if (x[1][0] - x[0][0] == 0 && x[3][0] - x[2][0] == 0) { return true; } else if (x[1][0] - x[0][0] == 0 || x[3][0] - x[2][0] == 0) { return false; } double a = (x[1][1] - x[0][1]) / (x[1][0] - x[0][0]); double b = (x[3][1] - x[2][1]) / (x[3][0] - x[2][0]); return a == b; } public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int n = stdIn.nextInt(); String[] result = new String[n]; for (int k = 0; k < n; k++) { double[][] a = new double[4][2]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { a[i][j] = stdIn.nextDouble(); } } if (solve(a)) { result[k] = "Yes"; } else { result[k] = "No"; } } for (int i = 0; i < n; i++) { System.out.println(result[i]); } } }
import java.util.Scanner; public class Main { public static boolean solve(double[][] x) { if (x[1][0] - x[0][0] == 0 && x[3][0] - x[2][0] == 0) { return true; } else if (x[1][0] - x[0][0] == 0 || x[3][0] - x[2][0] == 0) { return false; } double a = (x[1][1] - x[0][1]) / (x[1][0] - x[0][0]); double b = (x[3][1] - x[2][1]) / (x[3][0] - x[2][0]); return a == b; } public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int n = stdIn.nextInt(); String[] result = new String[n]; for (int k = 0; k < n; k++) { double[][] a = new double[4][2]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { a[i][j] = stdIn.nextDouble(); } } if (solve(a)) { result[k] = "YES"; } else { result[k] = "NO"; } } for (int i = 0; i < n; i++) { System.out.println(result[i]); } } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 491], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 491], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 491], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 491]]
3
375
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; class Main { public static void main(String[] args) throws IOException { doit(args, System.in, System.out); } static void doit(String[] args, InputStream in, PrintStream out) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); int n = Integer.parseInt(reader.readLine()); for (int i = 0; i < n; i++) { String line = reader.readLine(); String[] values = line.split(" "); double x1 = Double.parseDouble(values[0]); double y1 = Double.parseDouble(values[1]); double x2 = Double.parseDouble(values[2]); double y2 = Double.parseDouble(values[3]); double x3 = Double.parseDouble(values[4]); double y3 = Double.parseDouble(values[5]); double x4 = Double.parseDouble(values[6]); double y4 = Double.parseDouble(values[7]); double det = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3); out.println(det < 0.0001 ? "YES" : "NO"); } } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; class Main { public static void main(String[] args) throws IOException { doit(args, System.in, System.out); } static void doit(String[] args, InputStream in, PrintStream out) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); int n = Integer.parseInt(reader.readLine()); for (int i = 0; i < n; i++) { String line = reader.readLine(); String[] values = line.split(" "); double x1 = Double.parseDouble(values[0]); double y1 = Double.parseDouble(values[1]); double x2 = Double.parseDouble(values[2]); double y2 = Double.parseDouble(values[3]); double x3 = Double.parseDouble(values[4]); double y3 = Double.parseDouble(values[5]); double x4 = Double.parseDouble(values[6]); double y4 = Double.parseDouble(values[7]); double det = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3); out.println(det == 0.0 ? "YES" : "NO"); } } }
[["-", 0, 492, 3, 4, 0, 510, 15, 16, 17, 18], ["-", 0, 492, 3, 4, 0, 510, 15, 16, 12, 515], ["+", 0, 492, 3, 4, 0, 510, 15, 16, 17, 60], ["+", 0, 492, 3, 4, 0, 510, 15, 16, 12, 515]]
3
299
import java.io.IOException; import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); while (N-- > 0) { 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 x4 = sc.nextDouble(); double y4 = sc.nextDouble(); double[] AB = {x2 - x1, y2 - y1}, CD = {x4 - x3, y4 - y3}; double cross = AB[0] * CD[1] - AB[1] * CD[0]; if (cross < 1e-10) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
import java.io.IOException; import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); while (N-- > 0) { 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 x4 = sc.nextDouble(); double y4 = sc.nextDouble(); double[] AB = {x2 - x1, y2 - y1}, CD = {x4 - x3, y4 - y3}; double cross = Math.abs(AB[0] * CD[1] - AB[1] * CD[0]); if (cross < 1e-10) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
[["+", 8, 196, 0, 503, 49, 200, 51, 492, 500, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 0, 131], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["+", 0, 503, 49, 200, 51, 492, 3, 4, 0, 24], ["+", 0, 503, 49, 200, 51, 492, 3, 4, 0, 25]]
3
224
#include <stdio.h> int main(void) { float x1, y1, x2, y2, x3, y3, x4, y4; double dm, dn; int i, n; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%f %f %f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); dm = (y2 - y1) / (x2 - x1); dn = (y4 - y3) / (x4 - y3); if (dm == dn) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
#include <stdio.h> int main(void) { float x1, y1, x2, y2, x3, y3, x4, y4; double dm, dn; int i, n; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%f %f %f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); dm = (y2 - y1) / (x2 - x1); dn = (y4 - y3) / (x4 - x3); if (dm == dn) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
[["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22]]
0
150
#include <math.h> #include <stdio.h> #define delta 0.0000001 int main(void) { double d[20]; int n, i, j; double xd1, xd2, yd1, yd2; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 8; j++) { scanf("%lf", &d[j]); } xd1 = d[0] - d[2]; xd2 = d[4] - d[6]; yd1 = d[1] - d[3]; yd2 = d[5] - d[7]; if (fabs(xd1) < delta && fabs(xd2) < delta) { printf("YES\n"); } else if (fabs(xd1) < delta && fabs(xd2) < delta) { if (fabs(yd1 / xd1 - yd2 / xd2) < delta) { printf("YES\n"); } else { printf("NO\n"); } } else { printf("NO\n"); } } return 0; }
#include <math.h> #include <stdio.h> #define delta 0.0000001 int main(void) { double d[20]; int n, i, j; double xd1, xd2, yd1, yd2; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 8; j++) { scanf("%lf", &d[j]); } xd1 = d[0] - d[2]; xd2 = d[4] - d[6]; yd1 = d[1] - d[3]; yd2 = d[5] - d[7]; if (fabs(xd1) < delta && fabs(xd2) < delta) { printf("YES\n"); } else if (fabs(xd1) > delta && fabs(xd2) > delta) { if (fabs(yd1 / xd1 - yd2 / xd2) < delta) { printf("YES\n"); } else { printf("NO\n"); } } else { printf("NO\n"); } } return 0; }
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 47], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 47]]
0
232
#include <stdio.h> int main(void) { int i, j, n; float d[4], x[4], y[4]; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 4; j++) { scanf("%lf%lf", &x[j], &y[j]); } d[0] = x[1] - x[0]; d[1] = y[1] - y[0]; d[2] = x[3] - x[2]; d[3] = y[3] - y[2]; if (d[0] * d[3] == d[1] * d[2]) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
#include <stdio.h> int main(void) { int i, j, n; float d[4], x[4], y[4]; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 4; j++) { scanf("%f%f", &x[j], &y[j]); } d[0] = x[1] - x[0]; d[1] = y[1] - y[0]; d[2] = x[3] - x[2]; d[3] = y[3] - y[2]; if (d[0] * d[3] == d[1] * d[2]) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
197
#include <math.h> #include <stdio.h> const double eps = 1e-10; int n; // math.hライブラリでy1, y2...とかって変数名が使われてるらしい double ix1, ix2, ix3, ix4; double iy1, iy2, iy3, iy4; //増加率を見る方法 int solve() { double Ax = ix2 - ix1; double Ay = iy2 - iy1; double Bx = ix4 - ix3; double By = iy4 - iy3; double val = Ax * By - Ay * Bx; return (val < eps); } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &ix1, &iy1, &ix2, &iy2, &ix3, &iy3, &ix4, &iy4); if (solve()) { printf("YES\n"); } else { printf("NO\n"); } } }
#include <math.h> #include <stdio.h> const double eps = 1e-10; int n; // math.hライブラリでy1, y2...とかって変数名が使われてるらしい double ix1, ix2, ix3, ix4; double iy1, iy2, iy3, iy4; //増加率を見る方法 int solve() { double Ax = ix2 - ix1; double Ay = iy2 - iy1; double Bx = ix4 - ix3; double By = iy4 - iy3; double val = Ax * By - Ay * Bx; return (fabs(val) < eps); } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &ix1, &iy1, &ix2, &iy2, &ix3, &iy3, &ix4, &iy4); if (solve()) { printf("YES\n"); } else { printf("NO\n"); } } }
[["+", 0, 37, 0, 23, 0, 16, 31, 2, 63, 22], ["+", 0, 23, 0, 16, 31, 2, 3, 4, 0, 24], ["+", 0, 23, 0, 16, 31, 2, 3, 4, 0, 25]]
0
175
#include <stdio.h> int main(void) { int i, j, n; float m[8], e; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 8; j++) { scanf("%lf", &m[j]); } m[2] -= m[0]; m[3] -= m[1]; m[6] -= m[4]; m[7] -= m[5]; // e=(m[3]-m[1])*(m[6]-m[4])-(m[7]-m[5])*(m[2]-m[0]); if (m[7] * m[2] == m[6] * m[3]) printf("YES\n"); else printf("NO\n"); // printf("%s\n",(e==0)?"YES":"NO"); } return 0; }
#include <stdio.h> int main(void) { int i, j, n; float m[8], e; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 8; j++) { scanf("%f", &m[j]); } m[2] -= m[0]; m[3] -= m[1]; m[6] -= m[4]; m[7] -= m[5]; // e=(m[3]-m[1])*(m[6]-m[4])-(m[7]-m[5])*(m[2]-m[0]); if (m[7] * m[2] == m[6] * m[3]) printf("YES\n"); else printf("NO\n"); // printf("%s\n",(e==0)?"YES":"NO"); } return 0; } /* int main(){ int n; float x[4], y[4]; scanf("%d",&n); int i, loop; for(loop = 0; loop < n; loop++){ for(i = 0; i < 4; i++){ scanf("%f",&x[i]); scanf("%f",&y[i]); } x[1] -= x[0]; y[1] -= y[0]; x[3] -= x[2]; y[3] -= y[2]; if(x[3] * y[1] == y[3] * x[1]){ printf("YES\n"); }else{ printf("NO\n"); } } return 0; } */
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
161
#include <iostream> #include <string> using namespace std; int main() { int n; string str; /* while(cin >> str) { n = str.size(); for(int i=0;i<n;i++) { if((str[i] <= 122) && (str[i] >= 97)) { str[i] -= 32; } } if(str[n-1] == 46) cout << str; else cout << str << " "; } } */ getline(cin, str); n = str.size(); for (int i = 0; i < n; i++) { if ((str[i] <= 'Z') && (str[i] >= 'A')) { str[i] -= 32; } } cout << str << endl; }
#include <iostream> #include <string> using namespace std; int main() { int n; string str; /* while(cin >> str) { n = str.size(); for(int i=0;i<n;i++) { if((str[i] <= 122) && (str[i] >= 97)) { str[i] -= 32; } } if(str[n-1] == 46) cout << str; else cout << str << " "; } } */ getline(cin, str); n = str.size(); for (int i = 0; i < n; i++) { if ((str[i] <= 'z') && (str[i] >= 'a')) { str[i] -= 32; } } cout << str << endl; }
[["-", 51, 16, 31, 23, 0, 16, 12, 103, 0, 125], ["+", 51, 16, 31, 23, 0, 16, 12, 103, 0, 125], ["-", 51, 16, 12, 23, 0, 16, 12, 103, 0, 125], ["+", 51, 16, 12, 23, 0, 16, 12, 103, 0, 125]]
1
91
#include <ctype.h> #include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (isalpha(s[i])) { s[i] -= 32; } } cout << s << endl; }
#include <ctype.h> #include <iostream> #include <string> using namespace std; int main() { string s; getline(cin, s); for (int i = 0; i < s.size(); i++) { if (isalpha(s[i])) { s[i] -= 32; } } cout << s << endl; }
[["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25]]
1
68
#include <algorithm> #include <iostream> #include <string> char ToUpper(char cX) { return toupper(cX); } using namespace std; int main() { string in; cin >> in; transform(in.begin(), in.end(), in.begin(), ToUpper); cout << in << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> char ToUpper(char cX) { return toupper(cX); } using namespace std; int main() { string in; getline(cin, in); transform(in.begin(), in.end(), in.begin(), ToUpper); cout << in << endl; return 0; }
[["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25]]
1
69
#include <cstdio> using namespace std; int main(void) { char inp; while (scanf("%c", &inp) != EOF) { putchar((inp > 'a' && inp < 'z') ? inp - 32 : inp); } return 0; }
#include <cstdio> using namespace std; int main(void) { char inp; while (scanf("%c", &inp) != EOF) { putchar((inp >= 'a' && inp <= 'z') ? inp - 32 : inp); } return 0; }
[["-", 0, 41, 15, 23, 0, 16, 31, 16, 17, 47], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 20], ["-", 0, 41, 15, 23, 0, 16, 12, 16, 17, 18], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 17, 19]]
1
58
# coding=utf-8 sentence = input() sentence.upper() print(sentence)
# coding=utf-8 sentence = input() sentence = sentence.upper() print(sentence)
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 1, 0, 662, 12, 652, 63, 319, 500, 22]]
5
15
import cmath,math,sys z=0;p=90 for e in sys.stdin: r,d=map(int,e.split(',')) z+=cmath.rect(r,math.radians(p)) p-=d print(int(z.real),int(z.imag))
import cmath,math,sys z=0;p=90 for e in sys.stdin: r,d=map(int,e.split(',')) z+=cmath.rect(r,math.radians(p)) p-=d print(int(z.real),int(z.imag),sep='\n')
[["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 21], ["+", 0, 1, 0, 652, 3, 4, 0, 653, 141, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 653, 0, 32], ["+", 0, 652, 3, 4, 0, 653, 51, 557, 0, 654], ["+", 3, 4, 0, 653, 51, 557, 0, 6, 0, 44], ["+", 0, 652, 3, 4, 0, 653, 51, 557, 0, 655]]
5
71
import cmath,math,sys z=0;p=90 for e in sys.stdin: r,d=map(int,e.split(',')) z+=cmath.rect(r,math.radians(p)) p-=d print(int(z.real),int(z.imag))
import cmath,math,sys z=0;p=90 for e in sys.stdin: r,d=map(int,e.split(',')) z+=cmath.rect(r,math.radians(p)) p-=d print(int(z.real)) print(int(z.imag))
[["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 21], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25], ["+", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24]]
5
71
import math x = y = n= 0 while True: d,a = map(int,input().split(',')) if d == a == 0: break x += d*math.sin(math.radians(n)) y += d*math.cos(math.radians(n)) n+=a print(map(int,(x,y)),sep='\n')
import math x = y = n= 0 while True: d,a = map(int,input().split(',')) if d == a == 0: break x += d*math.sin(math.radians(n)) y += d*math.cos(math.radians(n)) n+=a print(*map(int,(x,y)),sep='\n')
[["+", 0, 652, 3, 4, 0, 652, 63, 661, 0, 48]]
5
91
from math import radians from cmath import rect z = 0 deg = 90 while True: r, d = map(int, input().split(',')) if r == d == 0: break z += rect(r, radians(deg)) deg -= d print(int(z.real), int(z.imag))
from math import radians from cmath import rect z = 0 deg = 90 while True: r, d = map(float, input().split(',')) if r == d == 0: break z += rect(r, radians(deg)) deg -= d print(int(z.real)) print(int(z.imag))
[["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 21], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25], ["+", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24]]
5
74
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String b = sc.next(); char[] a = b.toCharArray(); for (int i = 0; i < 26; ++i) { for (int j = 0; j < a.length; ++j) { if ('a' <= a[j] && a[j] <= 'z') { if (a[j] == 'z') { a[j] = 'a'; } else { ++a[j]; } } } String d = String.valueOf(a); if (d.contains("this") || d.contains("that") || d.contains("the")) { System.out.println(d); break; } } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String b = sc.nextLine(); char[] a = b.toCharArray(); for (int i = 0; i < 26; ++i) { for (int j = 0; j < a.length; ++j) { if ('a' <= a[j] && a[j] <= 'z') { if (a[j] == 'z') { a[j] = 'a'; } else { ++a[j]; } } } String ans = String.valueOf(a); if (ans.contains("this") || ans.contains("that") || ans.contains("the")) { System.out.println(ans); break; } } } } }
[["-", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["-", 0, 7, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 0, 7, 8, 196, 0, 503, 49, 200, 141, 22], ["-", 15, 15, 0, 16, 31, 16, 31, 492, 500, 22], ["+", 15, 15, 0, 16, 31, 16, 31, 492, 500, 22], ["-", 15, 15, 0, 16, 31, 16, 12, 492, 500, 22], ["+", 15, 15, 0, 16, 31, 16, 12, 492, 500, 22], ["-", 0, 57, 15, 15, 0, 16, 12, 492, 500, 22], ["+", 0, 57, 15, 15, 0, 16, 12, 492, 500, 22], ["-", 64, 196, 0, 1, 0, 492, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 492, 3, 4, 0, 22]]
3
196
import java.io.*; import java.util.regex.Pattern; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Pattern pattern = Pattern.compile("the|this|that"); String str; try { while ((str = br.readLine()) != null) { char[] ch = str.toCharArray(); for (int j = 0; !pattern.matcher(str).find() & j < 26; j++) { for (int i = 0; i < ch.length; i++) { if ('a' <= ch[i] && ch[i] < 'z') { ch[i]++; } else if (ch[i] == 'z') { ch[i] = 'a'; } } if (pattern.matcher(str).find()) { break; } } System.out.println(ch); } } catch (Exception e) { } } }
import java.io.*; import java.util.regex.Pattern; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Pattern pattern = Pattern.compile("the|this|that"); String str; try { while ((str = br.readLine()) != null) { char[] ch = str.toCharArray(); for (int j = 0; !pattern.matcher(str).find() & j < 26; j++) { for (int i = 0; i < ch.length; i++) { if ('a' <= ch[i] && ch[i] < 'z') { ch[i]++; } else if (ch[i] == 'z') { ch[i] = 'a'; } } if (pattern.matcher(String.valueOf(ch)).find()) { break; } } System.out.println(ch); } } catch (Exception e) { } } }
[["-", 15, 15, 0, 492, 500, 492, 3, 4, 0, 22], ["+", 0, 492, 500, 492, 3, 4, 0, 492, 500, 22], ["+", 0, 492, 500, 492, 3, 4, 0, 492, 0, 131], ["+", 0, 492, 500, 492, 3, 4, 0, 492, 141, 22], ["+", 500, 492, 3, 4, 0, 492, 3, 4, 0, 24], ["+", 500, 492, 3, 4, 0, 492, 3, 4, 0, 22], ["+", 500, 492, 3, 4, 0, 492, 3, 4, 0, 25]]
3
217
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); for (; scanner.hasNext();) { String in = scanner.nextLine(); int shift = getShift(in); String out = ""; for (int i = 0; i < in.length(); i++) { out += shiftWord(in.charAt(i), shift); } System.out.println(out); } } static int getShift(String str) { String[] word = str.split(" "); for (int i = 0; i < word.length; i++) { for (int j = 0; j < 26; j++) { String w = ""; for (int k = 0; k < word[i].length(); k++) { w += shiftWord(word[i].charAt(k), j); } if (w.equals("the") || w.equals("this") || w.equals("that")) { return j; } } } return 0; } static String shiftWord(char c, int shift) { char w = c; if ('a' <= c && c <= 'z') { w = (char)(c + shift); if (w > 'z') { w = (char)('a' + (w - 'z')); } } return String.valueOf(w); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); for (; scanner.hasNext();) { String in = scanner.nextLine(); int shift = getShift(in); String out = ""; for (int i = 0; i < in.length(); i++) { out += shiftWord(in.charAt(i), shift); } System.out.println(out); } } static int getShift(String str) { String[] word = str.split("[ .]"); for (int i = 0; i < word.length; i++) { for (int j = 0; j < 26; j++) { String w = ""; for (int k = 0; k < word[i].length(); k++) { w += shiftWord(word[i].charAt(k), j); } if (w.equals("the") || w.equals("this") || w.equals("that")) { return j; } } } return 0; } static String shiftWord(char c, int shift) { char w = c; if ('a' <= c && c <= 'z') { w = (char)(c + shift); if (w > 'z') { w = (char)('a' + (w - 'z') - 1); } } return String.valueOf(w); } }
[["-", 49, 200, 51, 492, 3, 4, 0, 5, 0, 491], ["+", 49, 200, 51, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 12, 499]]
3
324
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); String[] strtest = new String[26 * 3]; String[] ts = {"the", "this", "that"}; for (int i = 0; i < 26; i++) { for (int j = 0; j < 3; j++) { strtest[i * 3 + j] = ""; for (int k = 0; k < ts[j].length(); k++) { char tmp = (char)((ts[j].charAt(k) + i - 'a') % 26); strtest[i * 3 + j] = strtest[i * 3 + j] + (char)(tmp + 'a'); } } } String str = ""; String ans = ""; while (sc.hasNextLine() == true) { str = sc.nextLine(); ans = ""; String[] words = str.split(" "); int d = 0; boolean flag = false; for (int i = 0; i < words.length; i++) { String tmp = words[i]; if ((tmp.length() != 3) && (tmp.length() != 4)) continue; for (int j = 0; j < strtest.length; j++) { if (i == (words.length - 1)) { tmp.substring(0, (tmp.length() - 1)); } if (tmp.equals(strtest[j])) { d = j / 3; flag = true; break; } } if (flag) break; } for (int i = 0; i < str.length(); i++) { if ((str.charAt(i) != ' ') && (str.charAt(i) != '.')) { int tmp = (char)((str.charAt(i) - d - 'a') % 26); ans = ans + (char)(tmp + 'a'); } else { ans = ans + str.charAt(i); } } System.out.println(ans); } } }
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); String[] strtest = new String[26 * 3]; String[] ts = {"the", "this", "that"}; for (int i = 0; i < 26; i++) { for (int j = 0; j < 3; j++) { strtest[i * 3 + j] = ""; for (int k = 0; k < ts[j].length(); k++) { char tmp = (char)((ts[j].charAt(k) + i - 'a') % 26); strtest[i * 3 + j] = strtest[i * 3 + j] + (char)(tmp + 'a'); } } } String str = ""; String ans = ""; while (sc.hasNextLine() == true) { str = sc.nextLine(); ans = ""; String[] words = str.split(" "); int d = 0; boolean flag = false; for (int i = 0; i < words.length; i++) { String tmp = words[i]; if ((tmp.length() != 3) && (tmp.length() != 4)) continue; for (int j = 0; j < strtest.length; j++) { if (i == (words.length - 1)) { tmp.substring(0, (tmp.length() - 1)); } if (tmp.equals(strtest[j])) { d = j / 3; flag = true; break; } } if (flag) break; } for (int i = 0; i < str.length(); i++) { if ((str.charAt(i) != ' ') && (str.charAt(i) != '.')) { int tmp = (char)((str.charAt(i) - d - 'a' + 26) % 26); ans = ans + (char)(tmp + 'a'); } else { ans = ans + str.charAt(i); } } System.out.println(ans); } } }
[["+", 51, 23, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 51, 23, 0, 16, 31, 23, 0, 16, 12, 499]]
3
498
import java.util.*; class Main { private static final Scanner scan = new Scanner(System.in); public static void main(String args[]) { while (scan.hasNext()) { String line = scan.nextLine(); for (int i = 0; i < 26; i++) { String now = ""; StringBuffer sb = new StringBuffer(); for (int j = 0; j < line.length(); j++) { char cz = line.charAt(j); if (cz >= 'a' && cz <= 'z') { sb.append((char)('a' + (cz - 'a' - i) % 26)); } else { sb.append(cz); } } now = sb.toString(); boolean flag = false; for (int j = 0; j < now.length() - 2; j++) { char cs = now.charAt(j); char cs1 = now.charAt(j + 1); char cs2 = now.charAt(j + 2); if (cs == 't' && cs1 == 'h' && cs2 == 'e') { flag = true; break; } } for (int j = 0; j < now.length() - 3; j++) { char cs = now.charAt(j); char cs1 = now.charAt(j + 1); char cs2 = now.charAt(j + 2); char cs3 = now.charAt(j + 3); if (cs == 't' && cs1 == 'h') { if (cs2 == 'i' && cs3 == 's') { flag = true; break; } if (cs2 == 'a' && cs3 == 't') { flag = true; break; } } } if (flag) { System.out.printf("%s\n", now); break; } } } } }
import java.util.*; class Main { private static final Scanner scan = new Scanner(System.in); public static void main(String args[]) { while (scan.hasNext()) { String line = scan.nextLine(); for (int i = 0; i < 26; i++) { String now = ""; StringBuffer sb = new StringBuffer(); for (int j = 0; j < line.length(); j++) { char cz = line.charAt(j); if (cz >= 'a' && cz <= 'z') { sb.append((char)('a' + (cz - 'a' + i) % 26)); } else { sb.append(cz); } } now = sb.toString(); boolean flag = false; for (int j = 0; j < now.length() - 2; j++) { char cs = now.charAt(j); char cs1 = now.charAt(j + 1); char cs2 = now.charAt(j + 2); if (cs == 't' && cs1 == 'h' && cs2 == 'e') { flag = true; break; } } for (int j = 0; j < now.length() - 3; j++) { char cs = now.charAt(j); char cs1 = now.charAt(j + 1); char cs2 = now.charAt(j + 2); char cs3 = now.charAt(j + 3); if (cs == 't' && cs1 == 'h') { if (cs2 == 'i' && cs3 == 's') { flag = true; break; } if (cs2 == 'a' && cs3 == 't') { flag = true; break; } } } if (flag) { System.out.printf("%s\n", now); break; } } } } }
[["-", 0, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 17, 72]]
3
389
import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { while (sc.hasNext()) { char[] code = sc.nextLine().toCharArray(); decode(code); } } private static void decode(char[] code) { char[] decode = new char[code.length]; for (int i = 0; i < 26; i++) { for (int j = 0; j < code.length; j++) { if (code[j] == '.' || code[j] == ' ' || code[j] == '\n') { decode[j] = code[j]; } else { int num = (code[j] - 'a' + i) % 26; decode[j] = (char)('a' + num); } } String str = String.valueOf(decode); if (str.contains("the") && str.contains("this") && str.contains("that")) { System.out.println(str); break; } } } }
import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { while (sc.hasNext()) { char[] code = sc.nextLine().toCharArray(); decode(code); } } private static void decode(char[] code) { char[] decode = new char[code.length]; for (int i = 0; i < 26; i++) { for (int j = 0; j < code.length; j++) { if (code[j] == '.' || code[j] == ' ' || code[j] == '\n') { decode[j] = code[j]; } else { int num = (code[j] - 'a' + i) % 26; decode[j] = (char)('a' + num); } } String str = String.valueOf(decode); if (str.contains("the") || str.contains("this") || str.contains("that")) { System.out.println(str); break; } } } }
[["-", 0, 57, 15, 15, 0, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 15, 0, 16, 31, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 106]]
3
245
import java.io.*; import java.util.*; class Main { public static ArrayList<String> remove_sentence(String a) { ArrayList<String> b = new ArrayList<String>(); String[] strAry = a.split(" "); strAry[strAry.length - 1] = strAry[strAry.length - 1].replaceAll("\\.", ""); for (int i = 0; i < strAry.length; i++) { if (strAry[i].length() == 3 || strAry[i].length() == 4) b.add(strAry[i]); } return b; } public static String change_word(String str, int n) { String res = ""; int a; char[] a_c = str.toCharArray(); char buf; for (int i = 0; i < a_c.length; i++) { a = (int)a_c[i]; if ((a + n) > 122) { a = a + n - 25; a_c[i] = (char)a; } else { a = a + n; a_c[i] = (char)a; } } res = String.valueOf(a_c); return res; } public static void print_sentence(String str, int n) { int a; String res; ArrayList<Character> str_c = new ArrayList<Character>(); for (int j = 0; j < str.length(); j++) { str_c.add(str.charAt(j)); } for (int j = 0; j < str_c.size(); j++) { a = (int)str_c.get(j); if (97 <= a && a <= 122) { if ((a + n) >= 122) { a = a + n - 25; str_c.set(j, (char)a); } else { a = a + n; str_c.set(j, (char)a); } } } for (int i = 0; i < str_c.size(); i++) { System.out.print(str_c.get(i)); } System.out.print("\n"); } public static int check_sentence(ArrayList<String> a) { String b; int count = 0; ArrayList<String> target = new ArrayList<String>(); target.add("the"); target.add("this"); target.add("that"); for (int i = 0; i < a.size(); i++) { for (int j = 1; j < 25; j++) { for (int k = 0; k < target.size(); k++) { b = change_word(a.get(i), j); if (b.equals(target.get(k))) { count = j; break; } } if (count != 0) break; } if (count != 0) { break; } } return count; } public static ArrayList<Integer> dec_cae(ArrayList<String> a) { ArrayList<String> rem_str = new ArrayList<String>(); ArrayList<Integer> res = new ArrayList<Integer>(); for (int i = 0; i < a.size(); i++) { rem_str = remove_sentence(a.get(i)); res.add(check_sentence(rem_str)); } return res; } public static void main(String args[]) throws IOException { String str; ArrayList<String> inp = new ArrayList<String>(); ArrayList<Integer> count = new ArrayList<Integer>(); Scanner scan = new Scanner(System.in); scan.useDelimiter("\n"); while (scan.hasNext()) { str = scan.next(); inp.add(str); } count = (dec_cae(inp)); for (int i = 0; i < count.size(); i++) { print_sentence(inp.get(i), count.get(i)); } } }
import java.io.*; import java.util.*; class Main { public static ArrayList<String> remove_sentence(String a) { ArrayList<String> b = new ArrayList<String>(); String[] strAry = a.split(" "); strAry[strAry.length - 1] = strAry[strAry.length - 1].replaceAll("\\.", ""); for (int i = 0; i < strAry.length; i++) { if (strAry[i].length() == 3 || strAry[i].length() == 4) b.add(strAry[i]); } return b; } public static String change_word(String str, int n) { String res = ""; int a; char[] a_c = str.toCharArray(); char buf; for (int i = 0; i < a_c.length; i++) { a = (int)a_c[i]; if ((a + n) > 122) { a = a + n - 26; a_c[i] = (char)a; } else { a = a + n; a_c[i] = (char)a; } } res = String.valueOf(a_c); return res; } public static void print_sentence(String str, int n) { int a; String res; ArrayList<Character> str_c = new ArrayList<Character>(); for (int j = 0; j < str.length(); j++) { str_c.add(str.charAt(j)); } for (int j = 0; j < str_c.size(); j++) { a = (int)str_c.get(j); if (97 <= a && a <= 122) { if ((a + n) > 122) { a = a + n - 26; str_c.set(j, (char)a); } else { a = a + n; str_c.set(j, (char)a); } } } for (int i = 0; i < str_c.size(); i++) { System.out.print(str_c.get(i)); } System.out.print("\n"); } public static int check_sentence(ArrayList<String> a) { String b; int count = 0; ArrayList<String> target = new ArrayList<String>(); target.add("the"); target.add("this"); target.add("that"); for (int i = 0; i < a.size(); i++) { for (int j = 1; j < 26; j++) { for (int k = 0; k < target.size(); k++) { b = change_word(a.get(i), j); if (b.equals(target.get(k))) { count = j; break; } } if (count != 0) break; } if (count != 0) { break; } } return count; } public static ArrayList<Integer> dec_cae(ArrayList<String> a) { ArrayList<String> rem_str = new ArrayList<String>(); ArrayList<Integer> res = new ArrayList<Integer>(); for (int i = 0; i < a.size(); i++) { rem_str = remove_sentence(a.get(i)); res.add(check_sentence(rem_str)); } return res; } public static void main(String args[]) throws IOException { String str; ArrayList<String> inp = new ArrayList<String>(); ArrayList<Integer> count = new ArrayList<Integer>(); Scanner scan = new Scanner(System.in); scan.useDelimiter("\n"); while (scan.hasNext()) { str = scan.next(); inp.add(str); } count = (dec_cae(inp)); for (int i = 0; i < count.size(); i++) { print_sentence(inp.get(i), count.get(i)); } } }
[["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 499], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 499], ["-", 64, 196, 0, 57, 15, 15, 0, 16, 17, 20], ["+", 64, 196, 0, 57, 15, 15, 0, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 499], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 499]]
3
875
import java.util.Scanner; public class Main { private static Scanner scan; public static void main(String[] args) { scan = new Scanner(System.in); scan.useDelimiter("\\r\\n"); while (scan.hasNext()) { String str = scan.next(); int m = 0; String string = null; for (int i = 0; i < 26; i++) { char[] ch = str.toCharArray(); for (int j = 0; j < ch.length; j++) { if (ch[j] != '.' && ch[j] != ' ') { ch[j] = (char)('a' + (ch[j] - 'a' + i) % 26); } } string = String.valueOf(ch); if (string.indexOf("the") != -1 || string.indexOf("this") != -1 || string.indexOf("that") != -1) { m = 1; break; } } if (m == 1) { System.out.println(string); } else { System.out.println(); } } System.exit(0); } }
import java.util.Scanner; public class Main { private static Scanner scan; public static void main(String[] args) { scan = new Scanner(System.in); scan.useDelimiter("\\r\\n"); while (scan.hasNext()) { String str = scan.nextLine(); int m = 0; String string = null; for (int i = 0; i < 26; i++) { char[] ch = str.toCharArray(); for (int j = 0; j < ch.length; j++) { if (ch[j] != '.' && ch[j] != ' ') { ch[j] = (char)('a' + (ch[j] - 'a' + i) % 26); } } string = String.valueOf(ch); if (string.indexOf("the") != -1 || string.indexOf("this") != -1 || string.indexOf("that") != -1) { m = 1; break; } } if (m == 1) { System.out.println(string); } else { System.out.println(); } } System.exit(0); } }
[["-", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22]]
3
258
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { private static String str; private static String[] keys = {"the ", "this ", "that "}; public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while ((str = br.readLine()) != null) { for (int i = 0; i < 27; i++) { String newStr = decryption((char)i); if (newStr.indexOf(keys[0]) != -1 || newStr.indexOf(keys[1]) != -1 || newStr.indexOf(keys[2]) != -1) { System.out.println(newStr); break; } } } } private static String decryption(char cnt) { char[] ret = str.toCharArray(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == ' ' || c == '.' || c == '\n') { ret[i] = c; } else { int s = c - 1; if (s < 97) { s = 26 + s; } ret[i] = (char)s; } } return String.valueOf(ret); } }
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { private static String str; private static String[] keys = {"the ", "this ", "that "}; public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while ((str = br.readLine()) != null) { for (int i = 0; i < 27; i++) { String newStr = decryption(i); if (newStr.indexOf(keys[0]) != -1 || newStr.indexOf(keys[1]) != -1 || newStr.indexOf(keys[2]) != -1) { System.out.println(newStr); break; } } } } private static String decryption(int cnt) { char[] ret = str.toCharArray(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == ' ' || c == '.' || c == '\n') { ret[i] = c; } else { int s = c - cnt; if (s < 97) { s = 26 + s; } ret[i] = (char)s; } } return String.valueOf(ret); } }
[["-", 49, 200, 51, 492, 3, 4, 0, 74, 0, 24], ["-", 51, 492, 3, 4, 0, 74, 39, 506, 0, 517], ["-", 49, 200, 51, 492, 3, 4, 0, 74, 0, 25], ["-", 0, 195, 54, 495, 0, 496, 39, 506, 0, 517], ["+", 0, 195, 54, 495, 0, 496, 39, 506, 0, 507], ["-", 75, 196, 0, 503, 49, 200, 51, 16, 12, 499], ["+", 75, 196, 0, 503, 49, 200, 51, 16, 12, 22]]
3
287
#include <stdio.h> int c(char *p, int d) { return ((26 + *p - *(p + 1)) % 26 == d); } int a(char *p) { return ((*p < 'a') || (*p > 'z')); } char *decode(char *inbuf, int s) { int p = 0; while (inbuf[p]) { if (!a(&inbuf[p])) { int t = inbuf[p] + s; if (t > 'z') inbuf[p] = (char)(t - 26); else if (t < 'a') inbuf[p] = (char)(t + 26); else inbuf[p] = (char)t; } p++; } return (inbuf); } int main(s) { char inbuf[82]; while (fgets(inbuf, 80, stdin)) { char *p = inbuf - 1; while (*p++) { // s = 0; if ((c(p, 12)) && ((c(p + 1, 3) && a(p + 3)) || (c(p + 1, 7) && c(p + 2, 7) && a(p + 4)) || (c(p + 1, 2\ 5) && c(p + 2, 16) && a(p + 4)))) { s = 't' - *p; p += 3; break; } // p++; } printf("%s", decode(inbuf, s)); } return 0; }
#include <stdio.h> int c(char *p, int d) { return ((26 + *p - *(p + 1)) % 26 == d); } int a(char *p) { return ((*p < 'a') || (*p > 'z')); } char *decode(char *inbuf, int s) { int p = 0; while (inbuf[p]) { if (!a(&inbuf[p])) { int t = inbuf[p] + s; if (t > 'z') inbuf[p] = (char)(t - 26); else if (t < 'a') inbuf[p] = (char)(t + 26); else inbuf[p] = (char)t; } p++; } return (inbuf); } int main(s) { char inbuf[82]; while (fgets(inbuf, 80, stdin)) { char *p = inbuf - 1; while (*++p) { if ((c(p, 12)) && ((c(p + 1, 3) && a(p + 3)) || (c(p + 1, 7) && c(p + 2, 7) && a(p + 4)) || (c(p + 1, 2\ 5) && c(p + 2, 16) && a(p + 4)))) { s = 't' - *p; p += 3; break; } // p++; } printf("%s", decode(inbuf, s)); } return 0; }
[["-", 0, 52, 15, 23, 0, 66, 28, 27, 28, 22], ["+", 0, 52, 15, 23, 0, 66, 28, 27, 28, 22]]
0
345
#include <stdio.h> #include <string.h> int main() { int i, j; char s[90], t[90]; for (; gets(s);) { for (i = 0; i < 27; i++) { for (j = 0, memcpy(t, s, sizeof(s)); s[j]; j++) if (s[j] >= 97 && s[j] < 123) t[j] = s[j] + i < 123 ? s[j] + i : s[j] + i - 26; if (strstr(t, "the") || strstr(t, "this") || strstr(t, "that")) break; } puts(s); } return 0; }
#include <stdio.h> #include <string.h> int main() { int i, j; char s[90], t[90]; for (; gets(s);) { for (i = 0; i < 27; i++) { for (j = 0, memcpy(t, s, sizeof(s)); s[j]; j++) if (s[j] >= 97 && s[j] < 123) t[j] = s[j] + i < 123 ? s[j] + i : s[j] + i - 26; if (strstr(t, "the") || strstr(t, "this") || strstr(t, "that")) break; } puts(t); } return 0; }
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
0
163
#include <ctype.h> #include <stdio.h> #include <string.h> void caesar(const char *str, char *d_str, const int n) { int i, len; len = strlen(str); for (i = 0; i < len; i++) { if (isalpha(str[i])) d_str[i] = str[i] + n > 'z' ? str[i] + n - 24 : str[i] + n; else d_str[i] = str[i]; } d_str[i] = '\0'; } int main(void) { char str[100]; char d_str[100]; int n = 1; while (fgets(str, 100, stdin) != NULL) { n = 1; while (1) { caesar(str, d_str, n++); if (strstr(d_str, "the") || strstr(d_str, "this") || strstr(d_str, "that")) break; } printf("%s", d_str); } return 0; }
#include <ctype.h> #include <stdio.h> #include <string.h> void caesar(const char *str, char *d_str, const int n) { int i, len; len = strlen(str); for (i = 0; i < len; i++) { if (isalpha(str[i])) d_str[i] = str[i] + n > 'z' ? str[i] + n - 26 : str[i] + n; else d_str[i] = str[i]; } d_str[i] = '\0'; } int main(void) { char str[100]; char d_str[100]; int n = 1; while (fgets(str, 100, stdin) != NULL) { n = 1; while (1) { caesar(str, d_str, n++); if (strstr(d_str, "the") || strstr(d_str, "this") || strstr(d_str, "that")) break; } printf("%s", d_str); } return 0; }
[["-", 64, 1, 0, 11, 12, 41, 64, 16, 12, 13], ["+", 64, 1, 0, 11, 12, 41, 64, 16, 12, 13]]
0
215
#include <stdio.h> #include <string.h> int main() { char str[81]; // char cstr[80]; int s = 0; int i; char c; char *p; p = str; while ((c = getchar()) != EOF) { if (c != '\n') { *p = c; p++; } if (c == '\n') { *p = '\0'; p = str; s = 0; while (s <= 26) { for (i = 0; i < 80; i++) { if (str[i] >= 'a' && str[i] <= 'y') str[i]++; if (str[i] == 'z') str[i] = 'a'; } s++; if (strstr(str, "the") != NULL) break; if (strstr(str, "this") != NULL) break; if (strstr(str, "that") != NULL) break; } printf("%s\n", str); } } return 0; }
#include <stdio.h> #include <string.h> int main() { char str[81]; // char cstr[80]; int s = 0; int i; char c; char *p; p = str; while ((c = getchar()) != EOF) { if (c != '\n') { *p = c; p++; } if (c == '\n') { *p = '\0'; p = str; s = 0; while (s <= 26) { for (i = 0; i < 81; i++) { if (str[i] >= 'a' && str[i] <= 'y') { str[i]++; } else if (str[i] == 'z') { str[i] = 'a'; } } s++; if (strstr(str, "the") != NULL) break; if (strstr(str, "this") != NULL) break; if (strstr(str, "that") != NULL) break; } printf("%s\n", str); } } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 45], ["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 46]]
0
223
#include <stdio.h> #include <string.h> int main(void) { int i; int len; int f; int n; char str[128]; while (fgets(str, 100, stdin) != NULL) { f = 0; n = 0; while (n < 25) { len = strlen(str); for (i = 0; i < len; i++) { if (strncmp(&str[i], "the", 3) == 0) { f = 1; } if (strncmp(&str[i], "this", 4) == 0) { f = 1; } if (strncmp(&str[i], "that", 4) == 0) { f = 1; } } if (f == 1) { break; } for (i = 0; i < len; i++) { if (str[i] >= 'a' && str[i] < 'z') { str[i]++; } if (str[i] == 'z') { str[i] = 'a'; } } n++; } printf("%s", str); } return (0); }
#include <stdio.h> #include <string.h> int main(void) { int i; int len; int f; int n; char str[128]; while (fgets(str, 100, stdin) != NULL) { f = 0; n = 0; while (1) { len = strlen(str); for (i = 0; i < len; i++) { if (strncmp(&str[i], "the", 3) == 0) { f = 1; } if (strncmp(&str[i], "this", 4) == 0) { f = 1; } if (strncmp(&str[i], "that", 4) == 0) { f = 1; } } if (f == 1) { break; } for (i = 0; i < len; i++) { if (str[i] >= 'a' && str[i] < 'z') { str[i]++; } else if (str[i] == 'z') { str[i] = 'a'; } } n++; } printf("%s", str); } return (0); }
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 18], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 52, 15, 339, 51, 13], ["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
1
249
#include <cstring> #include <iostream> using namespace std; int main(void) { while (true) { string str; if (getline(cin, str)) break; ; while (true) { for (int i = 0; i < str.size(); i++) { if (isalpha(str[i]) && str[i] == 'z') { str[i] = 'a'; } else if (isalpha(str[i])) { str[i]++; } } if (str.find("that") != string::npos || str.find("the") != string::npos || str.find("the") != string::npos) break; } cout << str << endl; } return 0; }
#include <cstring> #include <iostream> using namespace std; int main(void) { while (true) { string str; if (!getline(cin, str)) break; ; while (true) { for (int i = 0; i < str.size(); i++) { if (isalpha(str[i]) && str[i] == 'z') { str[i] = 'a'; } else if (isalpha(str[i])) { str[i]++; } } if (str.find("that") != string::npos || str.find("this") != string::npos || str.find("the") != string::npos) break; } cout << str << endl; } return 0; }
[["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["-", 12, 16, 31, 2, 3, 4, 0, 5, 0, 6], ["+", 12, 16, 31, 2, 3, 4, 0, 5, 0, 6]]
1
163
#include <algorithm> #include <iostream> using namespace std; int main() { int n; long long m, a[5001]; a[0] = 0; while (cin >> n, n != 0) { for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } m = 0; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { m = max(m, a[j] - a[i]); } } cout << m << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int n; long long m, a[5001]; a[0] = 0; while (cin >> n, n != 0) { for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } m = -100000; for (int i = 0; i <= n; i++) { for (int j = i + 1; j <= n; j++) { m = max(m, a[j] - a[i]); } } cout << m << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 31, 22], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
1
142
#include <iostream> using namespace std; int S[5000]; int main() { int n; while (cin >> n, n) { S[0] = 0; int tmp, sum = 0; for (int i = 1; i < n; i++) { cin >> tmp; sum += tmp; S[i] = sum; } tmp = S[1] - S[0]; for (int i = 0; i < n; i++) { for (int j = i + 1; i < n; j++) { if (tmp < S[j] - S[i]) tmp = S[j] - S[i]; } } cout << tmp << endl; } return 0; }
#include <iostream> using namespace std; int S[5000]; int main() { int n; while (cin >> n, n) { S[0] = 0; int tmp, sum = 0; for (int i = 1; i <= n; i++) { cin >> tmp; sum += tmp; S[i] = sum; } tmp = S[1] - S[0]; for (int i = 0; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (tmp < S[j] - S[i]) tmp = S[j] - S[i]; } } cout << tmp << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
157
#include <cstdio> #include <iostream> using namespace std; int main() { int n, sum = 0, ans, sumkeep; while (cin >> n) { if (n == 0) break; ans = 0; sumkeep = 0; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { sumkeep = 0; for (int j = i; j < n; j++) { sumkeep += a[j]; if (i == 0) { ans = sumkeep; } else if (ans < sumkeep) { ans = sumkeep; } } } cout << ans << endl; } }
#include <cstdio> #include <iostream> using namespace std; int main() { int n, sum = 0, ans, sumkeep; while (cin >> n) { if (n == 0) break; ans = 0; sumkeep = 0; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { sumkeep = 0; for (int j = i; j < n; j++) { sumkeep += a[j]; if (i == 0 && j == 0) { ans = sumkeep; } else if (ans < sumkeep) { ans = sumkeep; } } } cout << ans << endl; } }
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
152
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, a[5000], s, ans; while (1) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } if (n == 0) { break; } ans = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= n - i; j++) { s = 0; if ((a[j] <= 0) || (a[j + i - 1] <= 0)) { goto A; } for (int k = j; k < j + i; k++) { s += a[k]; } if (ans < s) { ans = s; } A:; } } if (s == 0) { for (int i = 1; i < n; i++) { for (int j = 0; j < n - i; j++) { if (a[j] < a[j + 1]) { s = a[j]; a[j] = a[j + 1]; a[j + 1] = s; } } } ans = a[0]; } cout << ans << "\n"; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, a[5000], s, ans; while (1) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } if (n == 0) { break; } ans = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= n - i; j++) { s = 0; if ((a[j] <= 0) || (a[j + i - 1] <= 0)) { goto A; } for (int k = j; k < j + i; k++) { s += a[k]; } if (ans < s) { ans = s; } A:; } } if (ans == 0) { for (int i = 1; i < n; i++) { for (int j = 0; j < n - i; j++) { if (a[j] < a[j + 1]) { s = a[j]; a[j] = a[j + 1]; a[j + 1] = s; } } } ans = a[0]; } cout << ans << "\n"; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
292
#include <climits> #include <iostream> using namespace std; template <typename Type> long long Maximum_Sum_Sequence(Type N[], int size) { long long max = LLONG_MIN; for (int i = 0; i < size; i++) { long long sum = 0; for (int j = i; j < size; j++) { sum += N[j]; if (sum > max) { max = sum; } } } return max; } int main() { const int DATASETS = 1000; int n[DATASETS], a[DATASETS][5000], c = 0; while (true) { cin >> n[c]; if (n[c] == 0) { break; } for (int i = 0; i < n[c]; i++) { cin >> a[c][i]; } c++; } for (int i = 0; i < c; i++) { cout << Maximum_Sum_Sequence(a[i], n[i]) << endl; } return 0; }
#include <climits> #include <iostream> using namespace std; template <typename Type> long long Maximum_Sum_Sequence(Type N[], int size) { long long max = LLONG_MIN; for (int i = 0; i < size; i++) { long long sum = 0; for (int j = i; j < size; j++) { sum += N[j]; if (sum > max) { max = sum; } } } return max; } int main() { const int DATASETS = 100; int n[DATASETS], a[DATASETS][5000], c = 0; while (true) { cin >> n[c]; if (n[c] == 0) { break; } for (int i = 0; i < n[c]; i++) { cin >> a[c][i]; } c++; } for (int i = 0; i < c; i++) { cout << Maximum_Sum_Sequence(a[i], n[i]) << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
217
#include <iostream> int calcMaxSum(int amount_set); int main() { while (true) { int amount_set; std::cin >> amount_set; if (amount_set == 0) { break; } std::cout << calcMaxSum(amount_set) << std::endl; } return 0; } int calcMaxSum(int amount_set) { const int MAXNUMBER = 100000; //??\????????????????????§?????? int *data; data = new int[amount_set + 1]; int *sum = new int[amount_set + 1]; sum[0] = 0; //???????????????????????????????????´??????sum[0]??§?????? std::cin >> data[1]; //?????????????????±??? sum[1] = data[1]; //????????????????????? for (int number = 2; number <= amount_set; number++) { std::cin >> data[number]; //???????????????????????? sum[number] = sum[number - 1] + data[number]; // ????????´??° } int max = -MAXNUMBER; //????????????????????¨??¨-MAXNUMBER???????????????????????§???????????????????????????????°???? for (int number_big = 1; number_big < amount_set; number_big++) { for (int number_small = 0; number_small < number_big; number_small++) { if (sum[number_big] - sum[number_small] > max) { max = sum[number_big] - sum[number_small]; } } } delete[] data; delete[] sum; return max; }
#include <iostream> int calcMaxSum(int amount_set); int main() { while (true) { int amount_set; std::cin >> amount_set; if (amount_set == 0) { break; } std::cout << calcMaxSum(amount_set) << std::endl; } return 0; } int calcMaxSum(int amount_set) { const int MAXNUMBER = 100000; //??\????????????????????§?????? int *data; data = new int[amount_set + 1]; int *sum = new int[amount_set + 1]; sum[0] = 0; //???????????????????????????????????´??????sum[0]??§?????? std::cin >> data[1]; //?????????????????±??? sum[1] = data[1]; //????????????????????? for (int number = 2; number <= amount_set; number++) { std::cin >> data[number]; //???????????????????????? sum[number] = sum[number - 1] + data[number]; // ????????´??° } int max = -MAXNUMBER; //????????????????????¨??¨-MAXNUMBER???????????????????????§???????????????????????????????°???? for (int number_big = 1; number_big <= amount_set; number_big++) { for (int number_small = 0; number_small < number_big; number_small++) { if (sum[number_big] - sum[number_small] > max) { max = sum[number_big] - sum[number_small]; } } } delete[] data; delete[] sum; return max; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
250
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) int main() { int n, a[5010], sum[5010], res; while (true) { cin >> n; if (n == 0) break; rep(i, n) cin >> a[i]; sum[0] = 0; rep(i, n) sum[i + 1] = a[i] + sum[i]; res = 0; rep(i, n) rep(j, i) { res = max(res, sum[i + 1] - sum[j]); } cout << res << endl; } }
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) int main() { int n, a[5010], sum[5010], res; while (true) { cin >> n; if (n == 0) break; rep(i, n) cin >> a[i]; sum[0] = 0; rep(i, n) sum[i + 1] = a[i] + sum[i]; res = -1000000000; rep(i, n) rep(j, i + 1) { res = max(res, sum[i + 1] - sum[j]); } cout << res << endl; } }
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
1
141
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, num; vector<int> a; while (1) { cin >> n; if (n == 0) break; int Max = -100001; a.push_back(0); for (int i = 0; i < n; i++) { cin >> num; a.push_back(num); } for (int i = 1; i < n; i++) { a[i] = max(a[i], a[i] + a[i - 1]); Max = max(Max, a[i]); } cout << Max << endl; a.clear(); } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, num; vector<int> a; while (1) { cin >> n; if (n == 0) break; int Max = -100001; a.push_back(0); for (int i = 0; i < n; i++) { cin >> num; a.push_back(num); } for (int i = 1; i <= n; i++) { a[i] = max(a[i], a[i] + a[i - 1]); Max = max(Max, a[i]); } cout << Max << endl; a.clear(); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
152
#include <iostream> #include <vector> using namespace std; int main() { int n, num; vector<int> a; while (1) { int Max = -100000; cin >> n; if (n == 0) break; a.push_back(0); for (int i = 0; i < n; i++) { cin >> num; a.push_back(num); } for (int i = 1; i < n; i++) { a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i]; if (a[i] > Max) { Max = a[i]; } } cout << Max << endl; a.clear(); } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int n, num; vector<long int> a; while (1) { int Max = -1000001; cin >> n; if (n == 0) break; a.push_back(0); for (int i = 0; i < n; i++) { cin >> num; a.push_back(num); } //?????§??? for (int i = 1; i <= n; i++) { a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i]; if (a[i] > Max) { Max = a[i]; } } cout << Max << endl; a.clear(); } return 0; }
[["+", 39, 344, 3, 347, 0, 77, 39, 86, 0, 96], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
175
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (i = 0; i < n; ++i) #define each(itr, c) \ for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); itr++) #define mp make_pair #define pb push_back #define fi first #define sc second int main(int argc, char const *argv[]) { int i, j; while (1) { int n; cin >> n; if (n == 0) break; std::vector<long> a(n + 1); rep(i, n) scanf(" %ld", &a[i + 1]); std::vector<long> sum(n); // a[1]~a[i]?????? sum[0] = 0; for (i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i]; long ans = -5000 * 100000 - 1; for (i = 1; i <= n; ++i) { for (j = i; j <= n; ++j) { ans = max(ans, sum[j] - sum[i - 1]); } } std::cout << ans << std::endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (i = 0; i < n; ++i) #define each(itr, c) \ for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); itr++) #define mp make_pair #define pb push_back #define fi first #define sc second int main(int argc, char const *argv[]) { int i, j; while (1) { int n; cin >> n; if (n == 0) break; std::vector<long> a(n + 1); rep(i, n) scanf(" %ld", &a[i + 1]); std::vector<long> sum(n + 1); // a[1]~a[i]?????? sum[0] = 0; for (i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i]; long ans = -5000 * 100000 - 1; for (i = 1; i <= n; ++i) { for (j = i; j <= n; ++j) { ans = max(ans, sum[j] - sum[i - 1]); } } std::cout << ans << std::endl; } return 0; }
[["+", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13]]
1
236
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) break; int a[n], S[n], sum = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; S[i] = sum; } long max = S[0]; for (int i = 0; i < n; ++i) { if (S[i] > max) max = S[i]; for (int j = 0; j < n; ++j) { if (S[i] - S[j] > max) max = S[i] - S[j]; } } cout << max << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) break; int a[n], S[n], sum = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; S[i] = sum; } long max = S[0]; for (int i = 1; i < n; ++i) { if (S[i] > max) max = S[i]; for (int j = 0; j < i; ++j) { if (S[i] - S[j] > max) max = S[i] - S[j]; } } cout << max << endl; } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
1
174
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { int n; while (cin >> n && n > 0) { vector<int> a = vector<int>(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> s = vector<int>(1, 0); bool f = true; bool plus = false; for (int i = 0; i < n; i++) { if (a[i] >= 0) { if (!f) f = true; if (!plus) plus = true; s[0] += a[i]; } else if (s[0] > a[i]) { if (f) { s.push_back(s[0]); f = false; } s[0] += a[i]; } else { s[0] = 0; } } if (!plus) { int max = a[0]; for (int i = 1; i < n; i++) { if (max < a[i]) max = a[i]; } cout << max << endl; continue; } for (int i = 1; i < s.size(); i++) { if (s[i] > s[0]) s[0] = s[i]; } cout << s[0] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { int n; while (cin >> n && n > 0) { vector<int> a = vector<int>(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> s = vector<int>(1, 0); bool f = true; bool plus = false; for (int i = 0; i < n; i++) { if (a[i] >= 0) { if (!f) f = true; if (!plus) plus = true; s[0] += a[i]; } else if (s[0] > abs(a[i])) { if (f) { s.push_back(s[0]); f = false; } s[0] += a[i]; } else { s[0] = 0; } } if (!plus) { int max = a[0]; for (int i = 1; i < n; i++) { if (max < a[i]) max = a[i]; } cout << max << endl; continue; } for (int i = 1; i < s.size(); i++) { if (s[i] > s[0]) s[0] = s[i]; } cout << s[0] << endl; } return 0; }
[["+", 0, 57, 15, 339, 51, 16, 12, 2, 63, 22], ["+", 15, 339, 51, 16, 12, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 16, 12, 2, 3, 4, 0, 25]]
1
315
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s, a; while (cin >> n, n) { cin >> a; m = s = a; n--; while (n--) { cin >> a; if (s < 0) s = a; else s += a; m = max(s, m); } cout << m; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s, a; while (cin >> n, n) { cin >> a; m = s = a; n--; while (n--) { cin >> a; if (s < 0) s = a; else s += a; m = max(s, m); } cout << m << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
83
#include <stdio.h> int main(void) { int a[5010] = {}; int tr; int i, j; int n; int max; for (scanf("%d", &n); n; scanf("%d", &n)) { for (i = 0; i < 5010; i++) a[i] = 0; max = 0x80000000; for (i = 1; i <= n; i++) { scanf("%d", &tr); a[i] = a[i - 1] + tr; } for (i = 0; i < n; i++) for (j = i; j <= n; j++) { tr = a[j] - a[i - 1]; if (max < tr) max = tr; } printf("%d\n", max); } }
#include <stdio.h> int main(void) { int a[5010] = {}; int tr; int i, j; int n; int max; for (scanf("%d", &n); n; scanf("%d", &n)) { for (i = 0; i < 5010; i++) a[i] = 0; max = 0x80000000; for (i = 1; i <= n; i++) { scanf("%d", &tr); a[i] = a[i - 1] + tr; } for (i = 0; i < n; i++) for (j = i + 1; j <= n; j++) { tr = a[j] - a[i]; if (max < tr) max = tr; } printf("%d\n", max); } }
[["+", 0, 7, 8, 7, 10, 11, 12, 16, 17, 72], ["+", 0, 7, 8, 7, 10, 11, 12, 16, 12, 13], ["-", 12, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
183
#include <algorithm> #include <iostream> using namespace std; int main() { int n; int a[5000]; while (cin >> n && n > 0) { for (int i = 0; i < n; i++) cin >> a[i]; long long sum = 0, tmp = 0, ma = -100000; int m = -100000; bool flg = true; for (int i = 0; i < n; i++) { if (flg) m = max(m, a[i]); if (a[i] > 0) { flg = false; sum += a[i]; continue; } ma = ma > sum ? ma : sum; for (tmp = sum; i < n && a[i] <= 0; i++) { tmp += a[i]; } if (tmp > 0) sum = tmp; else sum = 0; } ma = ma > sum ? ma : sum; cout << (flg ? m : ma) << endl; } }
#include <algorithm> #include <iostream> using namespace std; int main() { int n; int a[5000]; while (cin >> n && n > 0) { for (int i = 0; i < n; i++) cin >> a[i]; long long sum = 0, tmp = 0, ma = -100000; int m = -100000; bool flg = true; for (int i = 0; i < n; i++) { if (flg) m = max(m, a[i]); if (a[i] >= 0) { flg = false; sum += a[i]; continue; } ma = ma > sum ? ma : sum; for (tmp = sum; i < n && a[i] < 0; i++) { tmp += a[i]; } i--; if (tmp > 0) sum = tmp; else sum = 0; } ma = ma > sum ? ma : sum; cout << (flg ? m : ma) << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 19], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 17, 68], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
1
212
#include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n && n) { vector<int> a(n, 0); for (int i = 0; i < n; ++i) { cin >> a[i]; } // ????????£?¶??????????????????§??£?¶???????dp??¨????????? vector<int> dp(n, 0); dp[0] = a[0]; int max = 0; for (int i = 1; i < n; ++i) { if (dp[i - 1] > 0) { dp[i] = dp[i - 1] + a[i]; } else { dp[i] = a[i]; } if (max < dp[i]) { max = dp[i]; } } cout << max << endl; } }
#include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n && n) { vector<int> a(n, 0); for (int i = 0; i < n; ++i) { cin >> a[i]; } // ????????£?¶??????????????????§??£?¶???????dp??¨????????? vector<int> dp(n, 0); dp[0] = a[0]; int max = dp[0]; for (int i = 1; i < n; ++i) { if (dp[i - 1] > 0) { dp[i] = dp[i - 1] + a[i]; } else { dp[i] = a[i]; } if (max < dp[i]) { max = dp[i]; } } cout << max << endl; } }
[["+", 8, 9, 0, 43, 49, 50, 51, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 70], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 73]]
1
171
#include <bits/stdc++.h> using namespace std; /*{{{*/ // template #define REP(i, n) for (int i = 0; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1 << 29 #define LINF LLONG_MAX / 3 #define MP make_pair #define PB push_back #define pb push_back #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define all(v) ALL(v) #define sz(x) (int)(x).size() #define debug(x) cerr << #x << ":" << x << endl #define debug2(x, y) cerr << #x << "," << #y ":" << x << "," << y << endl // struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_; struct Double { double d; explicit Double(double x) : d(x) {} }; ostream &operator<<(ostream &os, const Double x) { os << fixed << setprecision(20) << x.d; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } constexpr double eps = 1e-14; constexpr ll mod = 1e9 + 7; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; /*}}}*/ int n; constexpr long long minf = -100000 * 5000; void solve() { vector<int> a(n); rep(i, n) cin >> a[i]; vector<ll> sum(n + 10, 0); // sum[i] = a[0] + ... + a[i-1] for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i]; ll ans = minf - 10; rep(i, n) rep(j, n) if (i < j) { // k = a[i] + ... + a[j] ll k = sum[j + 1] - sum[i]; ans = max(ans, k); } cout << ans << endl; } int main() { while (cin >> n) { if (n == 0) break; solve(); } }
#include <bits/stdc++.h> using namespace std; /*{{{*/ // template #define REP(i, n) for (int i = 0; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1 << 29 #define LINF LLONG_MAX / 3 #define MP make_pair #define PB push_back #define pb push_back #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define all(v) ALL(v) #define sz(x) (int)(x).size() #define debug(x) cerr << #x << ":" << x << endl #define debug2(x, y) cerr << #x << "," << #y ":" << x << "," << y << endl // struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_; struct Double { double d; explicit Double(double x) : d(x) {} }; ostream &operator<<(ostream &os, const Double x) { os << fixed << setprecision(20) << x.d; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } constexpr double eps = 1e-14; constexpr ll mod = 1e9 + 7; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; /*}}}*/ int n; constexpr long long minf = -100000 * 5000; void solve() { vector<int> a(n); rep(i, n) cin >> a[i]; vector<ll> sum(n + 10, 0); // sum[i] = a[0] + ... + a[i-1] for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i]; ll ans = minf - 10; rep(i, n) rep(j, n) if (i <= j) { // k = a[i] + ... + a[j] ll k = sum[j + 1] - sum[i]; ans = max(ans, k); } cout << ans << endl; } int main() { while (cin >> n) { if (n == 0) break; solve(); } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
521
#include <iostream> using namespace std; int main() { int n = 1, count = 0; int a[10000]; while (cin >> n) { for (int i = 0; i < n; i++) { cin >> a[i]; } int sum = 0, max = -10000; for (int ai = 0; ai < n - 1; ai++) { sum = 0; for (int bi = ai; bi < n; bi++) { sum = sum + a[bi]; if (sum > max) { max = sum; } } } if (n == 0) break; cout << max << endl; } }
#include <iostream> using namespace std; int main() { int n = 1, count = 0; int a[10000]; while (cin >> n) { for (int i = 0; i < n; i++) { cin >> a[i]; } int sum = 0, max = -100000; for (int ai = 0; ai < n; ai++) { sum = 0; for (int bi = ai; bi < n; bi++) { sum = sum + a[bi]; if (sum > max) { max = sum; } } } if (n == 0) break; cout << max << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
140
#include <iostream> #include <vector> using namespace std; int main() { int n, k; vector<int> dp; while (true) { cin >> n; if (n == 0) return 0; for (int i = 0; i < n; i++) { cin >> k; if (i == 0) dp.push_back(k); else dp.push_back(max(dp[i - 1] + k, k)); } int max = dp[0]; for (int i = 0; i < n; i++) { if (max < dp[i]) { max = dp[i]; } } cout << max << endl; } }
#include <iostream> #include <vector> using namespace std; int main() { int n, k; vector<int> dp; while (true) { cin >> n; if (n == 0) return 0; for (int i = 0; i < n; i++) { cin >> k; if (i == 0) dp.push_back(k); else dp.push_back(max(dp[i - 1] + k, k)); } int max = dp[0]; for (int i = 0; i < n; i++) { if (max < dp[i]) { max = dp[i]; } } dp.clear(); cout << max << endl; } }
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
145
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define LOOP(i, x, n) for (int i = x; i < n; i++) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define MP make_pair #define FR first #define SC second #define int long long using namespace std; const int MOD = 1000000007; const int INF = 9000000009; const double eps = 1e-10; signed main() { int n; while (cin >> n, n) { vector<int> a(n); REP(i, n) { int x; cin >> x; a[i + 1] = a[i] + x; } int ans = -INF; REP(i, n + 1) LOOP(j, i + 1, n + 1) ans = max(ans, a[j] - a[i]); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define LOOP(i, x, n) for (int i = x; i < n; i++) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define MP make_pair #define FR first #define SC second #define int long long using namespace std; const int MOD = 1000000007; const int INF = 9000000009; const double eps = 1e-10; signed main() { int n; while (cin >> n, n) { vector<int> a(n + 100); REP(i, n) { int x; cin >> x; a[i + 1] = a[i] + x; } int ans = -INF; REP(i, n + 1) LOOP(j, i + 1, n + 1) ans = max(ans, a[j] - a[i]); cout << ans << endl; } return 0; }
[["+", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13]]
1
173
/*??£?¨?*/ #include <algorithm> #include <cstdio> #include <iostream> #include <math.h> #include <queue> #include <string.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) int main() { int max = 0, n, a[5001] = {0}, max_ = 0; while (cin >> n, n != 0) { max_ = 0; max = -1000000000000000000; rep(i, n) cin >> a[i]; rep(i, n) { for (int j = i; j < n; j++) { max_ += a[j]; if (max < max_) max = max_; } max_ = 0; } cout << max << endl; } return 0; }
/*??£?¨?*/ #include <algorithm> #include <cstdio> #include <iostream> #include <math.h> #include <queue> #include <string.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) int main() { int max = 0, n, a[5001] = {0}, max_ = 0; while (cin >> n, n != 0) { max_ = 0; max = -1000000000; rep(i, n) cin >> a[i]; rep(i, n) { for (int j = i; j < n; j++) { max_ += a[j]; if (max < max_) max = max_; } max_ = 0; } cout << max << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
1
151
#include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; int main() { long long n, a[5001], rui[5002] = {0}, ans[5002], cnt = 0; while (1) { cnt++; cin >> n; if (n == 0) break; for (int i = 0; i < n; ++i) { cin >> a[i]; rui[i + 1] = rui[i] + a[i]; } int max; max = -100001; for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { if (rui[j] - rui[i] > max) { max = rui[j] - rui[i]; } } } ans[cnt] = max; } for (int i = 1; i < cnt; ++i) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; int main() { long long n, a[5001], rui[5002] = {0}, ans[5002], cnt = 0; while (1) { cnt++; cin >> n; if (n == 0) break; for (int i = 0; i < n; ++i) { cin >> a[i]; rui[i + 1] = rui[i] + a[i]; } int max; max = -100001; for (int i = 0; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { if (rui[j] - rui[i] > max) { max = rui[j] - rui[i]; } } } ans[cnt] = max; } for (int i = 1; i < cnt; ++i) { cout << ans[i] << endl; } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
216
#include <stdio.h> int main() { int a; while (1) { scanf("%d", &a); if (a == 0) return 0; long long int n[10000]; for (int i = 0; i < a; i++) scanf("%lld", n + i); long long int dp[10000]; dp[0] = n[0]; long long int max = 0; for (int i = 1; i < a; i++) { if (dp[i - 1] > 0) dp[i] = dp[i - 1] + n[i]; else dp[i] = n[i]; if (max < dp[i]) max = dp[i]; } printf("%lld\n", max); } }
#include <stdio.h> int main() { int a; while (1) { scanf("%d", &a); if (a == 0) return 0; long long int n[10000]; for (int i = 0; i < a; i++) scanf("%lld", n + i); long long int dp[10000]; dp[0] = n[0]; long long int max = dp[0]; for (int i = 1; i < a; i++) { if (dp[i - 1] > 0) dp[i] = dp[i - 1] + n[i]; else dp[i] = n[i]; if (max < dp[i]) max = dp[i]; } printf("%lld\n", max); } }
[["+", 8, 9, 0, 43, 49, 50, 51, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 70], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 73]]
1
175
#include <cstdio> #include <iostream> using namespace std; long long a[5000]; int main() { int n; while (cin >> n && n) { long long ans = 1e9; for (int i = 0; i < n; i++) cin >> a[i], ans = max(ans, a[i]); long long sub = 0; for (int i = 0; i < n; i++) { sub += a[i]; if (sub < 0) { sub = 0; } else { ans = max(ans, sub); } } cout << ans << endl; } }
#include <cstdio> #include <iostream> using namespace std; long long a[5000]; int main() { int n; while (cin >> n && n) { long long ans = -1e9; for (int i = 0; i < n; i++) cin >> a[i], ans = max(ans, a[i]); long long sub = 0; for (int i = 0; i < n; i++) { sub += a[i]; if (sub < 0) { sub = 0; } else { ans = max(ans, sub); } } cout << ans << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
132
#include <algorithm> // require sort next_permutation count __gcd reverse etc. #include <cctype> // require tolower, toupper #include <cfloat> #include <climits> #include <cmath> // require fabs #include <cstdio> // require scanf printf #include <cstdlib> // require abs exit atof atoi #include <cstring> // require memset #include <ctime> // require srand #include <deque> #include <fstream> // require freopen #include <functional> #include <iomanip> // require setw #include <iostream> #include <limits> #include <map> #include <numeric> // require accumulate #include <queue> #include <set> #include <sstream> // require stringstream #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { // cut here before submit // freopen ("testcase.MSS", "r", stdin ); int n; while (scanf("%d", &n), n) { vector<int> a(n + 1, 0); vector<int> sum(n + 1, 0); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } // end rep for (int i = 1; i <= n; i++) { sum[i] = sum[i - 1] + a[i]; } // end for int res = 0; for (int i = 1; i <= n; i++) { int curr = 0; for (int j = i + 1; j <= n; j++) { curr = sum[j] - sum[i - 1]; res = max(res, curr); } // end for } // end for printf("%d\n", res); } // end loop return 0; }
#include <algorithm> // require sort next_permutation count __gcd reverse etc. #include <cctype> // require tolower, toupper #include <cfloat> #include <climits> #include <cmath> // require fabs #include <cstdio> // require scanf printf #include <cstdlib> // require abs exit atof atoi #include <cstring> // require memset #include <ctime> // require srand #include <deque> #include <fstream> // require freopen #include <functional> #include <iomanip> // require setw #include <iostream> #include <limits> #include <map> #include <numeric> // require accumulate #include <queue> #include <set> #include <sstream> // require stringstream #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { // cut here before submit // freopen ("testcase.MSS", "r", stdin ); int n; while (scanf("%d", &n), n) { vector<int> a(n + 1, 0); vector<int> sum(n + 1, 0); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } // end rep for (int i = 1; i <= n; i++) { sum[i] = sum[i - 1] + a[i]; } // end for int res = INT_MIN; for (int i = 1; i <= n; i++) { int curr = 0; for (int j = i; j <= n; j++) { curr = sum[j] - sum[i - 1]; res = max(res, curr); } // end for } // end for printf("%d\n", res); } // end loop return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 22], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
1
289
#include <algorithm> #include <climits> #include <cstdio> using namespace std; int main() { int n; while (scanf("%d", &n) && n != 0) { long long int a[n]; for (int i = 0; i < n; i++) scanf("%lld", &a[i]); long long int dp[n]; dp[0] = a[0]; long long int res = -100000 * 5000 - 1; for (int i = 1; i < n; i++) { dp[i] = max(a[i], dp[i - 1] + a[i]); res = max(res, dp[i]); } printf("%lld\n", res); } }
#include <algorithm> #include <climits> #include <cstdio> using namespace std; int main() { int n; while (scanf("%d", &n) && n != 0) { long long int a[n]; for (int i = 0; i < n; i++) scanf("%lld", &a[i]); long long int dp[n]; dp[0] = a[0]; long long int res = dp[0]; for (int i = 1; i < n; i++) { dp[i] = max(a[i], dp[i - 1] + a[i]); res = max(res, dp[i]); } printf("%lld\n", res); } }
[["-", 0, 43, 49, 50, 51, 16, 31, 16, 31, 13], ["-", 0, 43, 49, 50, 51, 16, 31, 16, 17, 48], ["-", 0, 43, 49, 50, 51, 16, 31, 16, 12, 13], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 17, 33], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 70], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 13], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 73]]
1
164
#include <cstdio> #include <vector> using namespace std; int main(void) { int n; while (scanf("%d", &n) && n) { int num[5001] = {0}; int total[5001] = {0}; int ans = -2000000000; for (int i = 0; i < n; i++) { scanf("%d", &num[i]); } for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { total[i] += num[j]; ans = max(ans, total[i]); } } printf("ans === %d\n", ans); } return 0; }
#include <cstdio> #include <vector> using namespace std; int main(void) { int n; while (scanf("%d", &n) && n) { int num[5001] = {0}; int total[5001] = {0}; int ans = -2000000000; for (int i = 0; i < n; i++) { scanf("%d", &num[i]); } for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { total[i] += num[j]; ans = max(ans, total[i]); } } printf("%d\n", ans); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
155
#include <stdio.h> int main(void) { while (1) { int n; scanf("%d", &n); if (n == 0) { break; } int a[5000]; int max; int i, j, k; for (i = 0; i < n; ++i) { scanf("%d", &a[i]); int sum = 0; for (j = i; j >= 0; --j) { sum += a[j]; } if ((i == 0 && j == 0) || sum > max) { max = sum; } } printf("%d\n", max); } return 0; }
#include <stdio.h> int main(void) { while (1) { int n; scanf("%d", &n); if (n == 0) { break; } int a[5000]; int max; int i, j; for (i = 0; i < n; ++i) { scanf("%d", &a[i]); int sum = 0; for (j = i; j >= 0; --j) { sum += a[j]; if ((i == 0 && j == 0) || sum > max) { max = sum; } } } printf("%d\n", max); } return 0; }
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 0, 21], ["-", 8, 9, 0, 52, 8, 9, 0, 43, 49, 22], ["-", 0, 7, 8, 9, 0, 7, 8, 9, 0, 46], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
1
144
#include <iostream> int main() { int n, v[5000], m; while (std::cin >> n, n) { for (int i = 0; i < n; i++) std::cin >> v[i]; m = v[0]; for (int i = 0; i < n; i++) for (int j = i, k = 0; j < n; j++, k += v[j]) if (k > m) m = k; std::cout << m << '\n'; } }
#include <iostream> int main() { int n, v[5000], m; while (std::cin >> n, n) { for (int i = 0; i < n; i++) std::cin >> v[i]; m = v[0]; for (int i = 0; i < n; i++) for (int j = i, k = v[i]; j < n; j++, k += v[j]) if (k > m) m = k; std::cout << m << '\n'; } }
[["-", 0, 7, 8, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 7, 10, 43, 49, 50, 51, 69, 28, 22], ["+", 10, 43, 49, 50, 51, 69, 341, 342, 0, 70], ["+", 10, 43, 49, 50, 51, 69, 341, 342, 0, 22], ["+", 10, 43, 49, 50, 51, 69, 341, 342, 0, 73]]
1
119
#include <iostream> int main() { int n, v[5000], m; while (std::cin >> n, m = n) { for (; m--;) std::cin >> v[m - 1]; m = *v; for (int i = 0; i < n; i++) for (int j = i, k = v[i]; j < n; j++, k += v[j]) m = k > m ? k : m; std::cout << m << '\n'; } }
#include <iostream> int main() { int n, v[5000], m; while (std::cin >> n, m = n) { for (; m--;) std::cin >> v[m]; m = *v; for (int i = 0; i < n; i++) for (int j = i, k = v[i]; j < n; j++, k += v[j]) m = k > m ? k : m; std::cout << m << '\n'; } }
[["-", 0, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
117
#include <iostream> main() { int n, v[5000], m; while (std::cin >> n, m = n) { for (; m--;) std::cin >> v[m]; m = *v; for (int i = 0; i++ < n;) for (int j = i, k = v[i]; j++ < n; k += v[j]) m = k > m ? k : m; std::cout << m << '\n'; } }
#include <iostream> main() { int n, v[5000], m; while (std::cin >> n, m = n) { for (; m--;) std::cin >> v[m]; m = *v; for (int i = 0; i < n; i++) for (int j = i, k = v[i]; j++ < n; k += v[j]) m = k > m ? k : m; std::cout << m << '\n'; } }
[["-", 8, 9, 0, 7, 15, 16, 31, 27, 17, 29], ["+", 0, 52, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 52, 8, 9, 0, 7, 26, 27, 17, 29]]
1
111
#include <algorithm> #include <iostream> using namespace std; int main(void) { int n, prev, d[5001], ret; while (1) { cin >> n; if (n == 0) break; cin >> d[0]; ret = d[0]; for (int i = 1; i < n; i++) { cin >> d[i]; for (int j = 0; j < i; j++) d[j] += d[i]; ret = max(*max_element(d, d + i), ret); } cout << ret << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main(void) { int n, prev, d[5001], ret; while (1) { cin >> n; if (n == 0) break; cin >> d[0]; ret = d[0]; for (int i = 1; i < n; i++) { cin >> d[i]; for (int j = 0; j < i; j++) d[j] += d[i]; ret = max(*max_element(d, d + i + 1), ret); } cout << ret << endl; } return 0; }
[["+", 0, 66, 28, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 66, 28, 2, 3, 4, 0, 16, 12, 13]]
1
132
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; double sq(double x) { return x * x; } int a[5001]; int main() { int n; while (cin >> n, n) { for (int i = 0; i < n; i++) { cin >> a[i + 1]; a[i + 1] += a[i]; } int ans = INT_MIN; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { ans = max(ans, a[i + 1] - a[j]); } } cout << ans << endl; } return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; double sq(double x) { return x * x; } int a[5001]; int main() { int n; while (cin >> n, n) { for (int i = 0; i < n; i++) { cin >> a[i + 1]; a[i + 1] += a[i]; } int ans = INT_MIN; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { ans = max(ans, a[i + 1] - a[j]); } } cout << ans << endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
170
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n; int a[5001]; int sum[5001]; main() { while (1) { int res = 0; scanf("%d", &n); if (n == 0) break; int sm = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sm += a[i]; sum[i] = sm; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int s = i - 1 < 0 ? 0 : sum[i - 1]; res = max(res, sum[j] - s); } } printf("%d\n", res); } }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n; int a[5001]; int sum[5001]; main() { while (1) { int res = -1000000; scanf("%d", &n); if (n == 0) break; int sm = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sm += a[i]; sum[i] = sm; } for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { int s = i - 1 < 0 ? 0 : sum[i - 1]; res = max(res, sum[j] - s); } } printf("%d\n", res); } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
1
185
#include <iostream> using namespace std; int main() { int n; int a; int sum; int sum2; int max; cin >> n; while (n) { cin >> sum; max = -100001; for (int i = 0; i < n - 1; i++) { cin >> sum2; sum += sum2; if (sum < sum2) { sum = sum2; } if (sum > max) { max = sum; } } cout << max << endl; cin >> n; } return 0; }
#include <iostream> using namespace std; int main() { int n; int a; int sum; int sum2; long int max; cin >> n; while (n) { cin >> sum; max = sum; for (int i = 0; i < n - 1; i++) { cin >> sum2; sum += sum2; if (sum < sum2) { sum = sum2; } if (sum > max) { max = sum; } } cout << max << endl; cin >> n; } return 0; }
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 22]]
1
108
#include <iostream> #include <string.h> int n; int a[5001]; void add(int i, int x) { while (i <= n) { a[i] += x; i += i & (-i); } return; } int sum(int i) { if (i == 0) return 0; int s = 0; while (i > 0) { s += a[i]; i -= i & (-i); } return s; } int main() { while (1) { memset(a, 0, sizeof(a)); std::cin >> n; if (!n) break; for (int i = 1; i <= n; i++) { int x; std::cin >> x; add(i, x); } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= n; j++) { ans = std::max(ans, sum(j) - sum(i - 1)); } } std::cout << ans << std::endl; } return 0; }
#include <iostream> #include <string.h> int n; int a[5001]; void add(int i, int x) { while (i <= n) { a[i] += x; i += i & (-i); } return; } int sum(int i) { if (i == 0) return 0; int s = 0; while (i > 0) { s += a[i]; i -= i & (-i); } return s; } int main() { while (1) { memset(a, 0, sizeof(a)); std::cin >> n; if (!n) break; for (int i = 1; i <= n; i++) { int x; std::cin >> x; add(i, x); } int ans = -100001; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= n; j++) { ans = std::max(ans, sum(j) - sum(i)); } } std::cout << ans << std::endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 16, 12, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 16, 12, 2, 3, 4, 0, 16, 12, 13]]
1
241
#include <stdio.h> #define INF 1000000000 int ar[5000]; int d[5001]; int max(int a, int b) { if (a >= b) return a; else return b; } int main() { int n, i, j; while (1) { scanf("%d", &n); if (n == 0) return 0; for (i = 0; i < n; i++) { scanf("%d", &ar[i]); } d[0] = 0; int ans = INF; for (i = 1; i < n + 1; i++) d[i] = d[i - 1] + ar[i - 1]; for (i = 0; i < n; i++) for (j = i + 1; j < n + 1; j++) { ans = max(ans, d[j] - d[i]); } printf("%d\n", ans); } }
#include <stdio.h> #define INF -1000000000 int ar[5000]; int d[5001]; int max(int a, int b) { if (a >= b) return a; else return b; } int main() { int n, i, j; while (1) { scanf("%d", &n); if (n == 0) return 0; for (i = 0; i < n; i++) { scanf("%d", &ar[i]); } d[0] = 0; int ans = INF; for (i = 1; i < n + 1; i++) d[i] = d[i - 1] + ar[i - 1]; for (i = 0; i < n; i++) for (j = i + 1; j < n + 1; j++) { ans = max(ans, d[j] - d[i]); } printf("%d\n", ans); } }
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
1
212
#include <iostream> using namespace std; int main() { int n; int b; int c; int d; int e; while (cin >> n) { if (n != 0) { break; } int a[n]; b = 0; while (b < n) { cin >> a[b]; b = b + 1; } d = a[0]; b = 0; while (b < n) { e = 0; c = b; while (c < n) { e = e + a[c]; if (e > d) { d = e; } c = c + 1; } b = b + 1; } cout << d << endl; } }
#include <iostream> using namespace std; int main() { int n; int b; int c; int d; int e; while (cin >> n) { if (n == 0) { break; } int a[n]; b = 0; while (b < n) { cin >> a[b]; b = b + 1; } d = a[0]; b = 0; while (b < n) { e = 0; c = b; while (c < n) { e = e + a[c]; if (e > d) { d = e; } c = c + 1; } b = b + 1; } cout << d << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
150
#include <iostream> using namespace std; int main() { while (1) { int n; cin >> n; if (!n) return 0; long long a[5010]; for (int i = 0; i < n; ++i) { cin >> a[i]; } long long ans; long long buf; for (int i = 0; i < n; ++i) { buf = 0; for (int j = i; j < n; ++j) { buf += a[j]; if (buf > ans) ans = buf; } } cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int main() { while (1) { int n; cin >> n; if (!n) return 0; long long a[5010]; for (int i = 0; i < n; ++i) { cin >> a[i]; } long long ans = -20000000000; long long buf; for (int i = 0; i < n; ++i) { buf = 0; for (int j = i; j < n; ++j) { buf += a[j]; if (buf > ans) ans = buf; } } cout << ans << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
133
#include <cstdio> #include <iostream> using namespace std; int num[5001]; /* int sum(int a,int b){ int s=0; for(int i=0;i<b;i++){ s+=num[a+i]; } return s; } */ int main() { int max; int n, sum; while (cin >> n, n) { max = -10000000; // int sum=-10000000; for (int i = 0; i < n; i++) { cin >> num[i]; } for (int i = 0; i < n - 1; i++) { sum = 0; for (int j = i; j < n; j++) { sum += num[j]; if (max < sum) max = sum; } } cout << max << endl; } }
#include <cstdio> #include <iostream> using namespace std; int num[5001]; /* int sum(int a,int b){ int s=0; for(int i=0;i<b;i++){ s+=num[a+i]; } return s; } */ int main() { int max; int n, sum; while (cin >> n, n) { max = -10000000; // int sum=-10000000; for (int i = 0; i < n; i++) { cin >> num[i]; } for (int i = 0; i < n; i++) { sum = 0; for (int j = i; j < n; j++) { sum += num[j]; if (max < sum) max = sum; } } cout << max << endl; } }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
128
#include <algorithm> #include <cstring> #include <iostream> #include <list> #include <map> #include <stack> #include <string> #include <vector> using namespace std; int main() { int n; int max, tmpmax1, tmpmax2; while (cin >> n && n != 0) { max = -100001; int *factor = new int[n]; for (int i = 0; i < n; i++) { cin >> factor[i]; } for (int i = 0; i < n - 1; i++) { tmpmax1 = 0; tmpmax2 = -100001; for (int j = i; j < n; j++) { tmpmax1 += factor[j]; if (tmpmax2 < tmpmax1) { tmpmax2 = tmpmax1; } } if (max < tmpmax2) { max = tmpmax2; } } delete[] factor; cout << max << endl; } return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <list> #include <map> #include <stack> #include <string> #include <vector> using namespace std; int main() { int n; int max, tmpmax1, tmpmax2; while (cin >> n && n != 0) { max = -100001; int *factor = new int[n]; for (int i = 0; i < n; i++) { cin >> factor[i]; } for (int i = 0; i < n; i++) { tmpmax1 = 0; tmpmax2 = -100001; for (int j = i; j < n; j++) { tmpmax1 += factor[j]; if (tmpmax2 < tmpmax1) { tmpmax2 = tmpmax1; } } if (max < tmpmax2) { max = tmpmax2; } } delete[] factor; cout << max << endl; } return 0; }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
172
#include <algorithm> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <stack> #include <vector> using namespace std; bool solve() { while (1) { int n; cin >> n; if (!n) break; vector<int> a(n, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } int sum = 0; for (int i = 0; i < n - 1; i++) { int sum2 = a[i]; if (sum < sum2) sum = sum2; for (int j = i + 1; j < n; j++) { sum2 += a[j]; if (sum < sum2) sum = sum2; } } cout << sum << endl; } return true; } int main() { cout.setf(ios::fixed); cout.precision(10); solve(); return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <stack> #include <vector> using namespace std; bool solve() { while (1) { int n; cin >> n; if (!n) break; vector<int> a(n, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } int sum = -100000; for (int i = 0; i < n; i++) { int sum2 = a[i]; if (sum < sum2) sum = sum2; for (int j = i + 1; j < n; j++) { sum2 += a[j]; if (sum < sum2) sum = sum2; } } cout << sum << endl; } return true; } int main() { cout.setf(ios::fixed); cout.precision(10); solve(); return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
198
#include <climits> #include <iostream> #include <iterator> #include <numeric> #include <vector> using namespace std; int main(void) { int N; while (cin >> N, N) { vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i]; vector<int> sums; sums.push_back(0); partial_sum(a.begin(), a.end(), back_inserter(sums)); int m = INT_MIN; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { m = max(m, sums[j + 1] - sums[i]); } } cout << m << endl; } }
#include <climits> #include <iostream> #include <iterator> #include <numeric> #include <vector> using namespace std; int main(void) { int N; while (cin >> N, N) { vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i]; vector<int> sums; sums.push_back(0); partial_sum(a.begin(), a.end(), back_inserter(sums)); int m = INT_MIN; for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { m = max(m, sums[j + 1] - sums[i]); } } cout << m << endl; } }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
1
163
#include <iostream> using namespace std; int main() { int n; int num[10000]; while (cin >> n, n) { int max = -100001; for (int i = 0; i < n; i++) cin >> num[i]; for (int i = 0; i < n - 1; i++) { int sum = 0; for (int j = i; j < n; j++) { sum += num[j]; if (sum > max) max = sum; } } cout << max << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n; int num[10000]; while (cin >> n, n) { int max = -100001; for (int i = 0; i < n; i++) cin >> num[i]; for (int i = 0; i < n; i++) { int sum = 0; for (int j = i; j < n; j++) { sum += num[j]; if (sum > max) max = sum; } } cout << max << endl; } return 0; }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
122
/*Filename: aoj0022.cpp *Author: Mushiyo */ #include <climits> #include <cmath> #include <iostream> using namespace std; int main() { int n = 0; while (cin >> n) { if (n == 0) { break; } int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int sum[n]; sum[0] = a[0]; for (int i = 1; i < n; ++i) { sum[i] = sum[i - 1] + a[i]; } int maxSum = INT_MIN; int minSum = INT_MAX; for (int i = 0; i < n; ++i) { maxSum = max(maxSum, sum[i] - minSum); minSum = min(minSum, sum[i]); } cout << maxSum << endl; } return 0; }
/*Filename: aoj0022.cpp *Author: Mushiyo */ #include <climits> #include <cmath> #include <iostream> using namespace std; int main() { int n = 0; while (cin >> n) { if (n == 0) { break; } int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int sum[n]; sum[0] = a[0]; for (int i = 1; i < n; ++i) { sum[i] = sum[i - 1] + a[i]; } int maxSum = INT_MIN; int minSum = 0; for (int i = 0; i < n; ++i) { maxSum = max(maxSum, sum[i] - minSum); minSum = min(minSum, sum[i]); } cout << maxSum << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
179
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { double x[4], y[4]; int n; scanf("%d", &n); while (n--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]); puts(abs((y[1] - y[0]) * (x[3] - x[2]) - (y[3] - y[2]) * (x[1] - x[0])) < 1e-12 ? "YES" : "NO"); } return (EXIT_SUCCESS); }
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { double x[4], y[4]; int n; scanf("%d", &n); while (n--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]); puts(fabs((y[1] - y[0]) * (x[3] - x[2]) - (y[3] - y[2]) * (x[1] - x[0])) < 1e-12 ? "YES" : "NO"); } return (EXIT_SUCCESS); }
[["-", 3, 4, 0, 41, 15, 16, 31, 2, 63, 22], ["+", 3, 4, 0, 41, 15, 16, 31, 2, 63, 22]]
0
173
#include <stdio.h> int main() { int n, i; double x[4], y[4], kat[2]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]); kat[0] = (y[1] - y[0]) / (x[1] - x[0]); kat[1] = (y[4] - y[3]) / (x[4] - x[3]); if (x[0] == x[1] && x[2] == x[3]) { printf("YES\n"); } else if (x[0] == x[1] || x[2] == x[3]) { printf("NO\n"); } else if (kat[0] == kat[1]) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
#include <stdio.h> int main() { int n, i; double x[4], y[4], kat[2]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]); kat[0] = (y[1] - y[0]) / (x[1] - x[0]); kat[1] = (y[2] - y[3]) / (x[2] - x[3]); if (x[0] == x[1] && x[2] == x[3]) { printf("YES\n"); } else if (x[0] == x[1] || x[2] == x[3]) { printf("NO\n"); } else if (kat[0] == kat[1]) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
[["-", 12, 16, 31, 23, 0, 16, 31, 69, 71, 13], ["+", 12, 16, 31, 23, 0, 16, 31, 69, 71, 13], ["-", 12, 16, 12, 23, 0, 16, 31, 69, 71, 13], ["+", 12, 16, 12, 23, 0, 16, 31, 69, 71, 13]]
0
269
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int n; int i; scanf("%d", &n); for (i = 0; i < n; i += 1) { double x1, y1, x2, y2, x3, y3, x4, y4; scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); x2 -= x1; y2 -= y1; x4 -= x3; y4 -= x4; if (x2 * y4 - y2 * x4 == 0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int n; int i; scanf("%d", &n); for (i = 0; i < n; i += 1) { double x1, y1, x2, y2, x3, y3, x4, y4; scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); x2 -= x1; y2 -= y1; x4 -= x3; y4 -= y3; if (x2 * y4 - y2 * x4 == 0.0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
0
145
#include <stdio.h> int main(void) { double x[4], y[4]; int n; scanf("%d", &n); while (n) { scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]); if ((y[1] - y[0]) / (x[1] - x[0]) == (y[3] - y[2]) / (x[3] - y[2])) { printf("YES\n"); } else { printf("NO\n"); } n--; } return (0); }
#include <stdio.h> int main(void) { double x[4], y[4]; int n; scanf("%d", &n); while (n) { scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]); if (((y[1] - y[0]) / (x[1] - x[0])) == ((y[3] - y[2]) / (x[3] - x[2]))) { printf("YES\n"); } else { printf("NO\n"); } n--; } return (0); }
[["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 57, 15, 23, 0, 16, 12, 23, 0, 24], ["-", 12, 16, 12, 23, 0, 16, 12, 69, 28, 22], ["+", 0, 16, 12, 23, 0, 16, 12, 69, 28, 22], ["+", 0, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
0
173
#include <stdio.h> main() { double x[100], y[100]; double a, b, c, d; int n, j; scanf("%d", &n); for (j = 0; j < n; j++) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[j], &y[j], &x[j + 1], &y[j + 1], &x[j + 2], &y[j + 2], &x[j + 3], &y[j]); a = x[j] - x[j + 1]; b = y[j] - y[j + 1]; c = x[j + 2] - x[j + 3]; d = y[j + 2] - y[j + 3]; if ((a * d - b * c) == 0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
#include <stdio.h> main() { double x[100], y[100]; double a, b, c, d; int n, j; scanf("%d", &n); for (j = 0; j < n; j++) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[j], &y[j], &x[j + 1], &y[j + 1], &x[j + 2], &y[j + 2], &x[j + 3], &y[j + 3]); a = x[j] - x[j + 1]; b = y[j] - y[j + 1]; c = x[j + 2] - x[j + 3]; d = y[j + 2] - y[j + 3]; if ((a * d - b * c) == 0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
[["+", 3, 4, 0, 66, 28, 69, 71, 16, 17, 72], ["+", 3, 4, 0, 66, 28, 69, 71, 16, 12, 13]]
0
221
#include <stdio.h> int main(void) { int n, i, j, k, jud[n]; double x[4], y[4]; scanf("%d", &n); for (j = 0; j < n; j++) { for (i = 0; i < 4; i++) { scanf("%lf", &x[i]); scanf("%lf", &y[i]); } if ((y[0] - y[1]) / (x[0] - x[1]) == (y[2] - y[3]) / (x[2] - x[3])) jud[j] = 0; else jud[j] = 1; } for (k = 0; k < n; k++) { if (jud[k] == 0) { printf("YES\n"); } else if (jud[k] == 1) { printf("NO\n"); } } return 0; }
#include <stdio.h> int main(void) { int n, i, j, k, jud[101]; double x[4], y[4]; scanf("%d", &n); for (j = 0; j < n; j++) { for (i = 0; i < 4; i++) { scanf("%lf", &x[i]); scanf("%lf", &y[i]); } if ((y[0] - y[1]) / (x[0] - x[1]) == (y[2] - y[3]) / (x[2] - x[3])) jud[j] = 0; else jud[j] = 1; } for (k = 0; k < n; k++) { if (jud[k] == 0) { printf("YES\n"); } else if (jud[k] == 1) { printf("NO\n"); } } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
0
222
#include <stdio.h> enum { PARALLEL, NOT_PARALLEL }; int parallel(float *xs, float *ys); int main(void) { float xs[4], ys[4]; int n; scanf("%d", &n); while (n--) { scanf("%f %f %f %f %f %f %f %f", &xs[0], &ys[0], &xs[1], &ys[1], &xs[2], &ys[2], &xs[3], &ys[3]); if (parallel(xs, ys) == PARALLEL) printf("YES\n"); else printf("NO\n"); } return 0; } int parallel(float *xs, float *ys) { float grad_a, grad_b; if (xs[0] == xs[1]) { if (xs[2] == xs[3]) { return PARALLEL; } return NOT_PARALLEL; } if (xs[2] == xs[3]) { return NOT_PARALLEL; } grad_a = (ys[1] - ys[0]) / (xs[1] - xs[0]); grad_b = (ys[3] - ys[2]) / (xs[1] - xs[0]); if (grad_a == grad_b) return PARALLEL; return NOT_PARALLEL; }
#include <stdio.h> enum { PARALLEL, NOT_PARALLEL }; int parallel(float *xs, float *ys); int main(void) { float xs[4], ys[4]; int n; scanf("%d", &n); while (n--) { scanf("%f %f %f %f %f %f %f %f", &xs[0], &ys[0], &xs[1], &ys[1], &xs[2], &ys[2], &xs[3], &ys[3]); if (parallel(xs, ys) == PARALLEL) printf("YES\n"); else printf("NO\n"); } return 0; } int parallel(float *xs, float *ys) { float grad_a, grad_b; if (xs[0] == xs[1]) { if (xs[2] == xs[3]) { return PARALLEL; } return NOT_PARALLEL; } if (xs[2] == xs[3]) { return NOT_PARALLEL; } grad_a = (ys[1] - ys[0]) / (xs[1] - xs[0]); grad_b = (ys[3] - ys[2]) / (xs[3] - xs[2]); if (grad_a == grad_b) return PARALLEL; return NOT_PARALLEL; }
[["-", 12, 16, 12, 23, 0, 16, 31, 69, 71, 13], ["+", 12, 16, 12, 23, 0, 16, 31, 69, 71, 13], ["-", 12, 16, 12, 23, 0, 16, 12, 69, 71, 13], ["+", 12, 16, 12, 23, 0, 16, 12, 69, 71, 13]]
0
278
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant //-------------------------------------------- const double EPS = 1e-8; const double PI = acos(-1.0); int main() { int N; cin >> N; for (; --N;) { double x[4], y[4]; REP(i, 4) cin >> x[i] >> y[i]; // x[0] -= x[1], y[0] -= y[1], x[2] -= x[3], y[2] -= y[3]; if (abs((x[0] - x[1]) * (y[2] - y[3]) - (x[2] - x[3]) * (y[0] - y[1])) < EPS) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); int main() { int N; cin >> N; for (; N--;) { double x[4], y[4]; REP(i, 4) cin >> x[i] >> y[i]; // x[0] -= x[1], y[0] -= y[1], x[2] -= x[3], y[2] -= y[3]; if (abs((x[0] - x[1]) * (y[2] - y[3]) - (x[2] - x[3]) * (y[0] - y[1])) < EPS) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 27, 17, 68], ["+", 0, 14, 8, 9, 0, 7, 15, 27, 17, 68]]
1
303
#include <complex.h> #include <iostream> #include <math.h> using namespace std; const double eps = pow(10, -11); double x[4], y[4]; int N; typedef complex<double> xy_t; double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); } int main() { cin >> N; //問題数 for (int t = 0; t < 4; ++t) { for (int i = 0; i < 4; ++i) cin >> x[i] >> y[i]; // x0,y0..x3,y3 xy_t a[2] = {xy_t(x[0], y[0]) - xy_t(x[1], y[1]), xy_t(x[2], y[2]) - xy_t(x[3], y[3])}; double s = cross_product(a[0], a[1]) / 2; bool p = abs(s) < eps; cout << (p ? "YES" : "NO") << endl; } }
#include <complex.h> #include <iostream> #include <math.h> using namespace std; const double eps = pow(10, -11); double x[4], y[4]; int N; typedef complex<double> xy_t; double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); } int main() { cin >> N; //問題数 for (int t = 0; t < N; ++t) { for (int i = 0; i < 4; ++i) cin >> x[i] >> y[i]; // x0,y0..x3,y3 xy_t a[2] = {xy_t(x[0], y[0]) - xy_t(x[1], y[1]), xy_t(x[2], y[2]) - xy_t(x[3], y[3])}; double s = cross_product(a[0], a[1]) / 2; bool p = abs(s) < eps; cout << (p ? "YES" : "NO") << endl; } }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22]]
1
225
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int n; double x1, x2, x3, x4, ya1, y2, y3, y4; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x1 >> ya1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if (x1 > x2) { double tmp = x1; x1 = x2; x2 = tmp; tmp = ya1; ya1 = y2; y2 = tmp; } if (x3 > x4) { double tmp = x3; x3 = x4; x4 = tmp; tmp = y3; y3 = y4; y4 = tmp; } if (x1 == x2) { if (x3 == x4) cout << "YES" << endl; else cout << "NO" << endl; } else { if (x3 == x4) cout << "NO" << endl; else { if ((y2 - ya1) / (x2 - x1) - (y4 - y3) / (x4 - x3) <= 0.00000000001) cout << "YES" << endl; else cout << "NO" << endl; } } } return 0; } /*@@@@@@@@@@@@@@@@@@@@@@@@@*/ /*@ @*/ /*@ debug output erased ? @*/ /*@ @*/ /*@@@@@@@@@@@@@@@@@@@@@@@@@*/
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int n; double x1, x2, x3, x4, ya1, y2, y3, y4; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x1 >> ya1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if (x1 > x2) { double tmp = x1; x1 = x2; x2 = tmp; tmp = ya1; ya1 = y2; y2 = tmp; } if (x3 > x4) { double tmp = x3; x3 = x4; x4 = tmp; tmp = y3; y3 = y4; y4 = tmp; } if (x1 == x2) { if (x3 == x4) cout << "YES" << endl; else cout << "NO" << endl; } else { if (x3 == x4) cout << "NO" << endl; else { if (abs((y2 - ya1) / (x2 - x1) - (y4 - y3) / (x4 - x3)) <= 0.00000000001) cout << "YES" << endl; else cout << "NO" << endl; } } } return 0; } /*@@@@@@@@@@@@@@@@@@@@@@@@@*/ /*@ @*/ /*@ debug output erased ? @*/ /*@ @*/ /*@@@@@@@@@@@@@@@@@@@@@@@@@*/
[["+", 0, 57, 15, 339, 51, 16, 31, 2, 63, 22], ["+", 3, 4, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 16, 12, 16, 12, 23, 0, 25]]
1
262
#include <iostream> using namespace std; void Solution() { int n; cin >> n; while (n--) { float x1, y1; float x2, y2; float x3, y3; float x4, y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; float ab = (y2 - y1) / (x2 - x1); // when "y / x = " another line's data, it can be seen as parallel float cd = (y4 - y3) / (x4 - x3); if (ab == cd) { cout << "Yes" << endl; } else { cout << "NO" << endl; } } } int main() { Solution(); return 0; }
// // practise.h // c++practise // // Created by Ubnit04 on 2015/06/10. // // #include <iostream> using namespace std; void Solution() { int n; cin >> n; while (n--) { float x1, y1; float x2, y2; float x3, y3; float x4, y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; float ab = (y2 - y1) / (x2 - x1); // when "y / x = " another line's data, it can be seen as parallel float cd = (y4 - y3) / (x4 - x3); if (ab == cd) { cout << "YES" << endl; } else { cout << "NO" << endl; } } } int main() { Solution(); return 0; }
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
135
#include <cmath> #include <iostream> #define rep(i, a, n) for (int i = a; i < n; i++) using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { double x1, y1, x2, y2, x3, y3, x4, y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; double a1 = x2 - x1; double b1 = y2 - y1; double a2 = x4 - x3; double b2 = y4 - y3; if (a1 * b2 - a2 * b1 < 1e-10) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <cmath> #include <iostream> #define rep(i, a, n) for (int i = a; i < n; i++) using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { double x1, y1, x2, y2, x3, y3, x4, y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; double a1 = x2 - x1; double b1 = y2 - y1; double a2 = x4 - x3; double b2 = y4 - y3; if (abs(a1 * b2 - a2 * b1) < 1e-10) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
[["+", 0, 57, 15, 339, 51, 16, 31, 2, 63, 22], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25]]
1
142
#include <iostream> using namespace std; int main() { float a, s, d, f, g, h, j, k; float q, w, e, r; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> s >> d >> f >> g >> h >> j >> k; q = d - a; w = f - s; e = j - g; r = k - h; int key = q * r - w * e; if (!key) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <iostream> using namespace std; int main() { float a, s, d, f, g, h, j, k; float q, w, e, r; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> s >> d >> f >> g >> h >> j >> k; q = d - a; w = f - s; e = j - g; r = k - h; float key = q * r - w * e; if (!key) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
[["-", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40]]
1
139
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> using namespace std; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { double x1, y1, x2, y2; double x3, y3, x4, y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if ((y2 - y1) * (x4 - x3) - (y4 - y3) * (x2 - x1) < 0.000001) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> using namespace std; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { double x1, y1, x2, y2; double x3, y3, x4, y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if (abs((y2 - y1) * (x4 - x3) - (y4 - y3) * (x2 - x1)) < 0.0000000001) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
[["+", 0, 57, 15, 339, 51, 16, 31, 2, 63, 22], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
132
// // // // // // // #include <complex> #include <iostream> using namespace std; typedef complex<double> xy_t; double cross_product(complex<double> a, complex<double> b) { return (conj(a) * b).imag(); } int main() { int n; //??????????????° cin >> n; while (n > 0) { complex<double> a, b, c, d, e, f; double real[4], imag[4]; for (int i = 0; i < 4; i++) cin >> real[i] >> imag[i]; a = xy_t(real[0], imag[0]); b = xy_t(real[1], imag[1]); c = xy_t(real[2], imag[2]); d = xy_t(real[3], imag[3]); e = a - b; f = c - d; double judge = cross_product(e, f); if (judge < 1e-11) cout << "YES" << endl; else cout << "NO" << endl; n--; } } /* complex?????????????§????????????§???????????????????????????????????§?????????????????°??¢????????¨??????????????? double????????£??????????????¨????????£???????????????????????¨????°???\?????????????????¶?????????????????????????????? ????????????????????¬????¬???????????????????????????? ????????\????????????????????????????????????????????¨??????????????? */
// // // // // // // #include <complex> #include <iostream> using namespace std; typedef complex<double> xy_t; double cross_product(complex<double> a, complex<double> b) { return (conj(a) * b).imag(); } int main() { int n; //??????????????° cin >> n; while (n > 0) { complex<double> a, b, c, d, e, f; double real[4], imag[4]; for (int i = 0; i < 4; i++) cin >> real[i] >> imag[i]; a = xy_t(real[0], imag[0]); b = xy_t(real[1], imag[1]); c = xy_t(real[2], imag[2]); d = xy_t(real[3], imag[3]); e = a - b; f = c - d; double judge = cross_product(e, f); if (abs(judge) < 1e-11) cout << "YES" << endl; else cout << "NO" << endl; n--; } } /* complex?????????????§????????????§???????????????????????????????????§?????????????????°??¢????????¨??????????????? double????????£??????????????¨????????£???????????????????????¨????°???\?????????????????¶?????????????????????????????? ????????????????????¬????¬???????????????????????????? ????????\????????????????????????????????????????????¨??????????????? */
[["+", 0, 57, 15, 339, 51, 16, 31, 2, 63, 22], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25]]
1
237
#include <algorithm> #include <iostream> using namespace std; int main() { int n; cin >> n; float point[4][2]; for (int i = 0; i < n; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 2; k++) { cin >> point[j][k]; } } if ((point[1][1] - point[0][1]) / (point[1][0] - point[0][0]) == ((point[3][1] - point[2][1]) / point[3][0] - point[2][0])) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int n; cin >> n; float point[4][2]; for (int i = 0; i < n; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 2; k++) { cin >> point[j][k]; } } if ((point[1][1] - point[0][1]) / (point[1][0] - point[0][0]) == (point[3][1] - point[2][1]) / (point[3][0] - point[2][0])) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
[["-", 12, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 339, 51, 16, 12, 16, 12, 23, 0, 24]]
1
182
#include <iostream> using namespace std; int main() { long double x1, y1, x2, y2, x3, y3, x4, y4; int n; cin >> n; int N[100]; for (int i = 0; i < n; i++) { cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if ((y1 - y2) / (x1 - x2) == (y3 - y4) / (x3 - x4)) { N[i] = 1; } else { N[i] = 0; } } for (int j = 0; j < n; j++) { if (N[j] = 1) { cout << "YES" << endl; } else if (N[j] = 0) { cout << "NO" << endl; } } return 0; }
#include <iostream> using namespace std; int main() { long double x1, y1, x2, y2, x3, y3, x4, y4; int n; cin >> n; int N[100]; for (int i = 0; i < n; i++) { cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if ((y1 - y2) / (x1 - x2) == (y3 - y4) / (x3 - x4)) { N[i] = 1; } else { N[i] = 0; } } for (int j = 0; j < n; j++) { if (N[j] == 1) { cout << "YES" << endl; } else if (N[j] == 0) { cout << "NO" << endl; } } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 75, 76, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 60]]
1
180
#include <algorithm> #include <cctype> #include <cmath> #include <iostream> #include <map> // pair #include <set> #include <stdio.h> #include <string> #include <vector> #define MAXSIZE 200000 #define PI 3.141592653589 using namespace std; template <typename T> T add(T a, T b) { return a + b; } namespace A { int f(void) { return 1; } } // namespace A int main() { int n; std::cin >> n; for (int i = 0; i < n; i++) { double x1, y1, x2, y2, x3, y3, x4, y4; std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if (((x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2)) < 0.001) { std::cout << "YES" << '\n'; } else { std::cout << "NO" << '\n'; } } }
#include <algorithm> #include <cctype> #include <cmath> #include <iostream> #include <map> // pair #include <set> #include <stdio.h> #include <string> #include <vector> #define MAXSIZE 200000 #define PI 3.141592653589 using namespace std; template <typename T> T add(T a, T b) { return a + b; } namespace A { int f(void) { return 1; } } // namespace A int main() { int n; std::cin >> n; for (int i = 0; i < n; i++) { double x1, y1, x2, y2, x3, y3, x4, y4; std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if (abs((x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2)) < 1.0e-10) { std::cout << "YES" << '\n'; } else { std::cout << "NO" << '\n'; } } }
[["+", 0, 57, 15, 339, 51, 16, 31, 2, 63, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
192
#include <cmath> #include <iostream> using namespace std; int main(void) { int n; cin >> n; for (int i = 0; i < n; ++i) { double x1, y1, x2, y2, x3, y3, x4, y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if ((x2 - x1) == 0 && (x4 - x3) == 0) cout << "YES" << endl; else { int d = abs((y2 - y1) * (x4 - x3) - (y4 - y3) * (x2 - x1)); cout << ((d <= 1e-10) ? "YES" : "NO") << endl; } } return 0; }
#include <cmath> #include <iostream> using namespace std; int main(void) { int n; cin >> n; for (int i = 0; i < n; ++i) { double x1, y1, x2, y2, x3, y3, x4, y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; if (((x2 - x1) == 0) && ((x4 - x3) == 0)) cout << "YES" << endl; else { double d = abs((y2 - y1) * (x4 - x3) - (y4 - y3) * (x2 - x1)); cout << ((d <= 1e-10) ? "YES" : "NO") << endl; } } return 0; }
[["+", 51, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 339, 51, 16, 31, 23, 0, 25], ["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 25], ["-", 0, 57, 75, 76, 0, 9, 0, 43, 39, 40], ["+", 0, 57, 75, 76, 0, 9, 0, 43, 39, 40]]
1
155
#include <complex> #include <iostream> int main() { const double E = 1e-10; int n; double x1, y1, x2, y2, x3, y3, x4, y4; std::cin >> n; while (n--) { std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; std::cout << (std::abs((y2 - y1) * (x4 - x3) - (y4 - y3) * (x2 - x1)) < E) ? "YES\n" : "NO\n"; } }
#include <complex> #include <iostream> int main() { const double E = 1e-10; int n; double x1, y1, x2, y2, x3, y3, x4, y4; std::cin >> n; while (n--) { std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; std::cout << ((std::abs((y2 - y1) * (x4 - x3) - (y4 - y3) * (x2 - x1)) < E) ? "YES\n" : "NO\n"); } }
[["+", 0, 16, 12, 23, 0, 41, 15, 23, 0, 24], ["+", 8, 9, 0, 1, 0, 16, 12, 23, 0, 25]]
1
116
#include <cmath> #include <iostream> using namespace std; int main() { int N; cin >> N; while (N--) { double x1, x2, x3, x4, y1, y2, y3, y4; cin >> x1 >> y1 >> x2 >> y2; cin >> x3 >> y3 >> x4 >> y4; x2 -= x1; y2 -= y1; x4 -= x3; y4 -= y3; cout << (fabs(x2 * y4 - x4 * y2 < 1e-5) ? "YES" : "NO") << endl; } }
#include <cmath> #include <iostream> using namespace std; int main() { int N; cin >> N; while (N--) { double x1, x2, x3, x4, y1, y2, y3, y4; cin >> x1 >> y1 >> x2 >> y2; cin >> x3 >> y3 >> x4 >> y4; x2 -= x1; y2 -= y1; x4 -= x3; y4 -= y3; cout << (fabs(x2 * y4 - x4 * y2) < 1e-10 ? "YES" : "NO") << endl; } }
[["-", 0, 41, 15, 2, 3, 4, 0, 16, 17, 18], ["-", 0, 41, 15, 2, 3, 4, 0, 16, 12, 13], ["+", 31, 16, 12, 23, 0, 41, 15, 16, 17, 18], ["+", 31, 16, 12, 23, 0, 41, 15, 16, 12, 13]]
1
108