<<":"<
#include <iostream>
#include <string.h>
using namespace std
;
int
main
(
void
)
{
int N
,aa
,bb
,cc
,i
,j
,count
=
0
;
char a
[
1002
],b
[
1002
],c
[
1003
];
cin
>>N
;
while
(N
--)
{
cin
>>a
>>b
;
count
++;
cout
<<
"Case "
<<count
<<
":"
<<endl
;
memset
(c
,
'0'
,
sizeof
(c
));
//初始化c字符数组使里面的元素全是0,注意最后一个位置要加上'/0'
strrev
(a
);
//字符串反转
strrev
(b
);
aa
=strlen
(a
);
bb
=strlen
(b
);
cc
=(aa
>=bb
)?aa
:bb
;
for
(i
=
0
,j
=
0
;i
<aa
;i
++,j
++)
{
c
[j
]=a
[i
];
}
for
(i
=
0
,j
=
0
;i
<bb
;i
++,j
++)
{
c
[j
]+=b
[i
]-
'0'
;
}
for
(i
=
0
;i
<=cc
;i
++)
{
if
(c
[i
]>=
58
)
{
c
[i
]=c
[i
]-
10
;
c
[i
+
1
]++;
}
}
if
(c
[cc
]!=
'0'
)
c
[cc
+
1
]=
'/0'
;
else
c
[cc
]=
'/0'
;
strrev
(a
);
strrev
(b
);
strrev
(c
);
if
(N
!=
0
)
cout
<<a
<<
" + "
<<b
<<
" = "
<<c
<<endl
<<endl
;
else
cout
<<a
<<
" + "
<<b
<<
" = "
<<c
<<endl
;
}
return
0
;
}
说真的这个题目做了我好久,因为开始的时候做出来的效果看上去是正确的,在VC上运行的结果和格式也完全满足题目的要求,但是提交的时候确实“wrong answer”。这种提示的错误真叫人无语,再加上自己A的题目比较少,没什么经验。至今都不知道那里错问题了。今天突然有想做这个题目了,由于前写天在网上看到了字符串反转和初始化的库函数,感觉做这个题目就简单了。结果终于被Accept了。很爽,发上来给大家品评一下!这个程序个人还是蛮满意的。
<<":"<
<<":"< 测试数据: <<":"<
<<":"< <<":"< <<":"< Sample Input <<":"<
<<":"<
2
1 2
112233445566778899 998877665544332211
Sample OutputCase 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110