PAT----1001. A+B Format (20)
2016-09-13 10:56
465 查看
Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
Input
Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.
Output
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input
Sample Output
import java.util.Scanner;
public class Main {
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
//int a=sc.nextInt();
//int b=sc.nextInt();
int ab=sc.nextInt()+sc.nextInt();
String s=ab+"";
StringBuffer sb=new StringBuffer(s);
for (int i = sb.length() - 3; i > 0 && sb.charAt(i - 1) != '-'; i -= 3) {
sb.insert(i, ",");
}
System.out.println(sb);
}
}
Input
Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.
Output
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input
-1000000 9
Sample Output
-999,991
import java.util.Scanner;
public class Main {
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
//int a=sc.nextInt();
//int b=sc.nextInt();
int ab=sc.nextInt()+sc.nextInt();
String s=ab+"";
StringBuffer sb=new StringBuffer(s);
for (int i = sb.length() - 3; i > 0 && sb.charAt(i - 1) != '-'; i -= 3) {
sb.insert(i, ",");
}
System.out.println(sb);
}
}
相关文章推荐
- PAT 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- 【PAT】1001. A+B Format (20)
- [PAT]1001. A+B Format (20)
- PAT甲题题解-1001. A+B Format (20)-字符串处理,水
- PAT:1001. A+B Format (20)
- 1001. A+B Format (20)-PAT甲级真题
- 【PAT】A1001. A+B Format (20)
- [PAT] 1001 A+B Format (20)
- PAT:1001. A+B Format (20)
- PAT 1001. A+B Format (20)
- PAT甲级 1001. A+B Format (20)--两种方法
- pat 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】
- 浙大PAT (Advanced Level) Practise 1001 A+B Format (20)
- 浙江大学PAT_甲级_1001. A+B Format (20)
- Java - PAT - 1001. A+B Format (20)
- PAT甲级-1001. A+B Format (20)
- PAT Advanced 1001. A+B Format (20) (C语言实现)