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 2138. The Good, the Bad and the Ugly

Тесть №9ю Не могу понять в чем ошибаюсь, первая задача моя на Олимпиаде. Учусь пока. Подскажите.
Posted by Vyacheslav 23 Oct 2020 15:46
Тест №9 не проходит.

//2138. Хороший, плохой, злой
public class olimpSumDif {
    StreamTokenizer in;
    //StringTokenizer inString;
    PrintWriter     out;
        public static void main(String[] args) throws IOException
        {
            new olimpSumDif().run();
        }

        int nextInt() throws IOException
        {
            in.nextToken();
            return (int)in.nval;
        }

        String nextString() throws IOException
        {
        in.nextToken();
        return (String) in.sval;
        }

        void run() throws IOException
        {
            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
            //inString = new StringTokenizer (new BufferedReader(new InputStreamReader(System.in)));
            out = new PrintWriter(System.out);
            solve();
            out.flush();
        }

        void solve() throws IOException
        {
            String b = nextString();
            int a = nextInt();
            out.print(integerToSingleDigitAndReverse(a));
        }
        long integerToSingleDigitAndReverse(long number) {
            int digit = (int) number;
            ArrayList<Long> array = new ArrayList();
            for (int i = 0; i < 4; i++)
                array.add((long)Math.floor(digit/Math.pow(256,i) % 256));
            Collections.reverse(array);
            number = 0;
            for (int i = 0; i < 4; i++)
                number = number +  array.get(i)*((long)Math.pow(256, i)) ;
            return number;
        }

}
Re: Тесть №9ю Не могу понять в чем ошибаюсь, первая задача моя на Олимпиаде. Учусь пока. Подскажите.
Posted by Vyacheslav 23 Oct 2020 18:45
Отбой, решил. В граничном случае использовал int, нужен long.