1001. A+b Format (20) time limit ms memory limit 65536 KB code length limit 16000 B procedure StandardAuthor Chen, Yue
Calculate A + B and output the sum in standard format – that's, the digits must be separated to groups of three by COM Mas (unless there is less than four digits).
Input
Each input file contains the one test case. Each case contains a pair of integers a and b where-1000000 <= A, b <= 1000000. The numbers is separated by a space.
Output
For each test case, you should output the sum of A and B on one line. The sum must is written in the standard format.
Sample Input
-1000000 9
Sample Output
-999,991
My Code:
1 Package_1001;2 3 ImportJava.text.DecimalFormat;4 ImportJava.text.NumberFormat;5 ImportJava.util.Scanner;6 7 Public classMain {8 9 Public Static voidMain (string[] args) {TenScanner sc=NewScanner (system.in); One while(Sc.hasnext ()) { A intA=sc.nextint (); - intb=sc.nextint (); - intans=a-b; theNumberFormat format=NewDecimalFormat ("#,###,###"); -String str=NewString (); -Str=Format.format (ans); - System.out.println (str); + } - } +}
1002. A+b for polynomials (25) time limit MS Memory limit 65536 KB code length limit 16000 B procedure StandardAuthor Chen, Yue
This is supposed to find a+b where A and B are both polynomials.
Input
Each input file contains the one test case. Each case occupies 2 lines, and all line contains the information of a polynomial:k N1 aN1 N2 aN2 ... NK ANK, where K is the number of nonzero terms in the polynomial, Ni and ANi (I=1, 2, ..., K) are the exponents and Coeffi Cients, respectively. It is given that 1 <= K <= 10,0 <= NK < ... < N2 < N1 <=1000.
Output
For each test case you should output the sum of A and B on one line, with the same format as the input. Notice that there must is NO extra space at the end of each line. Accurate to 1 decimal place.
Sample Input
2 1 2.4 0 3.22 2 1.5 1 0.5
Sample Output
3 2 1.5 1 2.9 0 3.2
1 Package_1002;2 3 ImportJava.util.Scanner;4 5 Public classMain {6 7 Public Static voidMain (string[] args) {8 9 intN;Ten Double[] A=New Double[10]; One Double[] b=New Double[10]; A Double[] ans=New Double[10]; - inti; - intMax=0; the - //First line -Scanner scan=NewScanner (system.in); -n=scan.nextint (); + for(i=0;i<n;i++){ - intindex=scan.nextint (); +a[index]=scan.nextdouble (); A } at - //Second Line -scan=NewScanner (system.in); -n=scan.nextint (); - for(i=0;i<n;i++){ - intindex=scan.nextint (); inb[index]=scan.nextdouble (); - } to + for(i=0;i<10;i++){ -ans[i]=b[i]+A[i]; the } * for(i=9;i>=0;i--){ $ if(ans[i]!=0){Panax NotoginsengMax=i+1; - Break; the } + } A System.out.print (max); the for(i=max-1;i>=0;i--) {//guaranteed one decimal normalized output +System.out.format ("%d%.1f", I,ans[i]); - } $ System.out.println (); $ } - -}
Pat Brush Problem (Java language)