ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1404. Easy to Hack!

Компилятор JAVA
Posted by Ilya Shuvaloff 17 Feb 2017 16:11
Доброго всем времени суток.
Прошу помочь разобраться, в чем может состоять проблема моего кода. В NetBeans все компилируется без проблем, здесь же выдается ошибка RuntimeError. Я здесь впервые, поэтому прошу не судить (З.Ы. Руководство по написанию java скриптов прочел и до сих пор не нашел ошибки). Заранее всем спасибо.

Hi all!
I'm asking you for help, cause my script cannot be run by server java compiler. In NetBeans it works well, but here that's a RuntimeError.
Thank you in anvance.

import java.util.Scanner;
import java.io.PrintWriter;

public class Cryptography {

    final String alphabetStr = "abcdefghijklmnopqrstuvwxyz";

    public static void main(String[] args) {
        new Cryptography().run();
    }

    void run() {
        Scanner in = new Scanner(System.in, "ISO-8859-1");
    PrintWriter out = new PrintWriter(System.out);

    String word = in.next();

        out.println( descript(word) );
    out.flush();
    }

    String descript(String word) {
        int index = alphabetStr.indexOf( word.charAt( word.length()-1 ) );

        if ( word.length()==1 ) return ("" + alphabetStr.charAt(index-5));

        index -= alphabetStr.indexOf( word.charAt( word.length()-2 ) );
        if ( index<0 ) index += 26;
        return descript(word.substring(0, word.length()-1)) + alphabetStr.charAt(index);
    }

}

Edited by author 17.02.2017 16:13

Edited by author 17.02.2017 16:15
Re: Компилятор JAVA
Posted by ToadMonster 17 Feb 2017 17:19
If "Runtime error" happened than your program compiled successful and crashed while running. As you have RE on 4th test your program passed first 3 tests.


> int index = alphabetStr.indexOf( word.charAt( word.length()-1 ) );
> if ( word.length()==1 ) return ("" + alphabetStr.charAt(index-5));

How should it work for string "a" for example?
Re: Компилятор JAVA
Posted by Ilya Shuvaloff 17 Feb 2017 17:37
Just before you answered i've found exactly this problem. Thank you!