zoukankan
html css js c++ java
大整数运算 add 提交hdoj 1002题
Code
#include
<
string
>
#include
<
iostream
>
using
namespace
std;
void
add(
string
a,
string
b,
char
sum[],
int
&
count)
{
int
len1
=
a.length();
int
len2
=
b.length();
int
i
=
len1
-
1
,j
=
len2
-
1
,temp
=
0
,carry
=
0
;
count
=
0
;
while
(i
>=
0
&&
j
>=
0
)
{
temp
=
a[i]
-
'
0
'
+
b[j]
-
'
0
'
+
carry;
sum[count
++
]
=
temp
%
10
+
'
0
'
;
carry
=
temp
/
10
;
--
i;
--
j;
}
while
(i
>=
0
)
{
temp
=
a[i]
-
'
0
'
+
carry;
sum[count
++
]
=
temp
%
10
+
'
0
'
;
carry
=
temp
/
10
;
--
i;
}
while
(j
>=
0
)
{
temp
=
b[j]
-
'
0
'
+
carry;
sum[count
++
]
=
temp
%
10
+
'
0
'
;
carry
=
temp
/
10
;
--
j;
}
if
(carry
>
0
)
{
sum[count
++
]
=
'
1
'
;
}
}
void
print(
char
arr[],
int
len)
{
int
i;
for
(i
=
len
-
1
;i
>=
0
;
--
i)
{
cout
<<
arr[i];
}
cout
<<
endl;
}
int
main()
{
string
a,b;
char
sum[
2000
];
int
count,cs;
cin
>>
count;
for
(cs
=
1
;cs
<=
count;cs
++
)
{
int
len;
cin
>>
a
>>
b;
cout
<<
"
Case
"
<<
cs
<<
"
:
"
<<
endl;
cout
<<
a
<<
"
+
"
<<
b
<<
"
=
"
;
add(a,b,sum,len);
print(sum,len);
if
(cs
!=
count)
cout
<<
endl;
}
return
0
;
}
查看全文
相关阅读:
获取html
asp.net上传图片自动生成缩略图功能代码
又发现了一个好东西zTree,KindEditor,Kissy Editor,脚本安全类工具Burp suite
C#.Net网络程序开发Socket篇
简单验证码的制作
C#:文件创建、复制、移动、删除
日常提醒2 (delphi源码)
time_t和SYSTEMTIME 与TDateTime的转换 (转)
简单的图片对比函数
胃总是涨 大便不成形 打嗝 口有异味?
原文地址:https://www.cnblogs.com/Knuth/p/1575672.html
最新文章
如何做好CRM系统的选型?
让销售人员爱上CRM系统
CRM系统让繁杂的销售工作变得简单
[导入]使用Flash打造可定义界面风格的文件上传控件
[导入]文件同步精灵(初版) 协议介绍(源码公开)
[导入]用C#实现Socket5代理服务(源码公开)
shell for、while用法
shell if参数用法
shell shift用法
shell 大括号和小括号
热门文章
shell sed用法
实用脚本 5 通过进程名批量杀死进程
shell cut用法
shell脚本事例 获取当前日期的前一天日期
程序在Linux下前后台切换
五度圈详解
asp.net下载文件几种方式
asp.net cookies用法
简单实用的分页类
ASP.NET数据格式的Format DataFormatString
Copyright © 2011-2022 走看看