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 #2
Posted by sanbir 11 Mar 2013 00:12
Hello ladies and gentelmen! Could you please explain me what is wrong with my code and why it fails the test #2. I have read in a previous post that

Result for test
4
9 0
5 4
5 4
5 5
must be "0000"

and my code passes it.
Thank you in advance. Here is my code:

import java.util.*;
import java.text.DecimalFormat;

public class JavaApplication8 {

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int a, b, r = 0, plus = 0;
        String pattern = "";

        for(int i=0;i<n;i++)
        {
            a=sc.nextInt();
            b=sc.nextInt();
            plus = a+b;
            r += (plus%10) * Math.pow(10, n-i-1);
            if(plus>9)r += Math.pow(10, n-i);
            pattern+="0";
        }

        r%=Math.pow(10,n);
        sc.close();

        DecimalFormat myFormatter = new DecimalFormat(pattern);
        String output = myFormatter.format(r);
        System.out.println(output);
    }

}