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 1048. Superlong Sums

WA#4.Where is my mistake?
Posted by plankton(Vologda ML) 8 Mar 2011 21:38
import java.io.*;

class Assert {
    static void check(boolean e) {
        if (!e) {
            throw new Error();
        }
    }
}

class Scanner {

    StreamTokenizer in;

    Scanner(InputStream is) {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
        in.resetSyntax();
        in.whitespaceChars(0, 32);
        in.wordChars(33, 255);
    }

    String next() {
        try {
            in.nextToken();
            Assert.check(in.ttype == in.TT_WORD);
            return in.sval;
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}

public class Main {

    PrintWriter out;
    Scanner in;

    void solve() {
        int n = in.nextInt();
        int a = in.nextInt() + in.nextInt();
        int b;
        for (int i = 1; i < n; i++) {
            b = in.nextInt() + in.nextInt();
            out.print(a + b / 10);
            a = b % 10;
        }
        out.print(a);
    }

    void run() {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);
        try {
            solve();
        } finally {
            out.close();
        }
    }

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

}
Re: WA#4.Where is my mistake?
Posted by fainéant 28 Mar 2011 20:02
I tried it without exceptions, and I got TLE.
try this test :

3
1 0
8 1
9 1

Try using java.util.Scanner and remove the two first classes.

Edited by author 28.03.2011 20:08