Skip to content

Instantly share code, notes, and snippets.

@jcchurch
Last active December 24, 2015 23:09
Show Gist options
  • Save jcchurch/6878175 to your computer and use it in GitHub Desktop.
Save jcchurch/6878175 to your computer and use it in GitHub Desktop.
import java.util.*;
import java.lang.*;
public class Taunting {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNextInt()) {
double thisx = 0;
double thisy = 0;
double size = 0;
int n = scan.nextInt();
scan.nextLine();
String line = scan.nextLine();
String[] parts = line.split(",");
double firstx = Double.parseDouble(parts[0]);
double firsty = Double.parseDouble(parts[1]);
double previousx = firstx;
double previousy = firsty;
for (int i = 2; i <= n; i++) {
line = scan.nextLine();
parts = line.split(",");
thisx = Double.parseDouble(parts[0]);
thisy = Double.parseDouble(parts[1]);
double miny = thisy;
double maxy = previousy;
if (previousy < thisy) {
miny = previousy;
maxy = thisy;
}
double timedelta = thisx - previousx;
size += (timedelta * miny) + (timedelta * (maxy-miny) * 0.5);
previousx = thisx;
previousy = thisy;
}
System.out.printf("%.2f to %.2f: %.4f\n", firstx, thisx, size);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment