PAT 1001

题目 : A+B Format

分值 : 20
难度 : 简单题
思路 : A+B 然后递归打印就好了
坑点 : 每三个字节有一个 001 的问题,需要 %03d了解一下

具体代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using namespace std ;
void print(int c )
{
int d = c /1000 ;
if(d != 0 )
{
print(d) ;
printf(",%03d",c%1000);
}
else
cout<< c%1000 ;



}
int main() {
int a , b ;
cin >> a >> b ;
int c = a+b ;
if(c<0)
{
cout<< "-" ;
c = -c ;
}
print(c) ;
}