It is attempt to solve second task from Code Jam 2014. Unfortunately, I have an InputMisMatchException? I think problem is that first number is not double. How I should to read such information? Link to task.
Input:
4
30.0 1.0 2.0
30.0 2.0 100.0
30.50000 3.14159 1999.19990
500.0 4.0 2000.0
My Java code:
public class CookieClickerAlpha {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = (int) sc.nextDouble();
double priceForFarm, plusCookies, goal;
double currentTime = 0.0, timeWithFarm,
timeWithoutFarm, timeForFarm, resultTime;
double currCookies = 0.0, cookiesPerSec = 2.0;
for (int i = 0; i < n; i++) {
priceForFarm = sc.nextDouble();
plusCookies = sc.nextDouble();
goal = sc.nextDouble();
while (currCookies < goal) {
timeForFarm = (priceForFarm - currCookies) / cookiesPerSec;
timeWithFarm = timeForFarm +
goal / (cookiesPerSec + plusCookies);
timeWithoutFarm = (goal - currCookies) / cookiesPerSec;
if (timeWithFarm < timeWithoutFarm) {
currCookies = 0.0;
cookiesPerSec += plusCookies;
currentTime += timeForFarm;
}
else {
currentTime += goal / cookiesPerSec;
currCookies = goal;
}
}
pw.print("Case #" + (i + 1) + ": ");
pw.println(currentTime);
}
sc.close();
pw.close();
}
}