Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation error and runtime error in Google Kick Start Tests

Tags:

java

I am trying to solve this problem from google kick start 2018 round A problem 1 Even Digits. I have put all of my code below which is working perfectly fine in eclipse ide but when I take this code and paste it into Google Kick Start website and run a test it gives a Compilation Error.

mesg: ttyname failed: Inappropriate ioctl for device Solution.java:2: error: class Main is public, should be declared in a file named Main.java public class Main{

Problem:
Supervin has a unique calculator. This calculator only has a display, a plus button, and a minus button. Currently, the integer N is displayed on the calculator display.

Pressing the plus button increases the current number displayed on the calculator display by 1. Similarly, pressing the minus button decreases the current number displayed on the calculator display by 1. The calculator does not display any leading zeros. For example, if 100 is displayed on the calculator display, pressing the minus button once will cause the calculator to display 99.

Supervin does not like odd digits, because he thinks they are "odd". Therefore, he wants to display an integer with only even digits in its decimal representation, using only the calculator buttons. Since the calculator is a bit old and the buttons are hard to press, he wants to use a minimal number of button presses.

Please help Supervin to determine the minimum number of button presses to make the calculator display an integer with no odd digits.

Input
The first line of the input gives the number of test cases, T. T test cases follow. Each begins with one line containing an integer N: the integer initially displayed on Supervin's calculator.

Output
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimum number of button presses, as described above.

Limits
1 ≤ T ≤ 100. Time limit: 20 seconds per test set. Memory limit: 1GB.

Small dataset (Test set 1 - Visible) 1 ≤ N ≤ 105.

Large dataset (Test set 2 - Hidden) 1 ≤ N ≤ 1016.

Sample
Input
4
42
11
1
2018

Output
Case #1: 0
Case #2: 3
Case #3: 1
Case #4: 2

In Sample Case #1, the integer initially displayed on the calculator has no odd digits, so no button presses are needed.

In Sample Case #2, pressing the minus button three times will cause the calculator to display 8. There is no way to satisfy the requirements with fewer than three button presses.

In Sample Case #3, either pressing the minus button once (causing the calculator to display 0) or pressing the plus button once will cause the calculator to display an integer without an odd digit.

In Sample Case #4, pressing the plus button twice will cause the calculator to display 2020. There is no way to satisfy the requirements with fewer than two button presses.

I removed public from the class and then ran the test but then it give a runtime error but in eclipse it works ok.

import java.util.Scanner;
class Main{
    static long input_long;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("No of Test cases:");
        int T = sc.nextInt();
        String[] longArr = new String[T];
        for(int i = 0;i < T;i++){
            longArr[i] = sc.next();
        }
        for(int i = 0;i < longArr.length;i++) {
            if(checkEven(longArr[i])) {
                System.out.println("Case #"+(i+1)+": 0");
            }
            else {
                System.out.println("Case #"+(i+1)+": "+result(longArr[i]));
            }
        }
        sc.close();
    }
    static long result(String s) {
        input_long = Long.valueOf(s);
        long ret;
        char[] arr = s.toCharArray();
        if((arr[0]-'0')%2==0) {
            return ret = increment(input_long);
        }
        else {
            return ret = decrement(input_long);
        }
    }
    static boolean checkEven(String a)
    static long increment(long l)
    static long decrement(long l)
like image 812
qasimmehdi Avatar asked Sep 23 '19 20:09

qasimmehdi


People also ask

How many rounds of Google kickstart are there?

There are eight (8) rounds in the Google Kickstart Contest. You are free to participate in any or all of the Rounds.

Is Python good for Google kickstart?

Can I use Python in Google kickstart? The answer is "yes" – Python is a good tool for competitions with the "open input" format.

Which languages are allowed in Google kickstart?

The new platform enables interactive problems in which your code communicates with our code and it supports the following: Bash, C, C++, C# (mono), Go, Haskell (ghc), Java 8, Javascript (nodejs), Python 2, Python 3, PHP, and Ruby.


1 Answers

Change your class name from "Main" to "Solution"

like image 69
dak Avatar answered Nov 15 '22 06:11

dak