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
;
}
查看全文
相关阅读:
Python基础
XML文件的基础使用
正则表达式的基本使用
hafs的java_api(转载)
HDFS常用的Shell命令(转载)
安装hadoop2.4.1
配置JDK环境变量
准备Linux环境
Winform窗体屏蔽Alt+F4强制关闭
leetcode 0214
原文地址:https://www.cnblogs.com/Knuth/p/1575672.html
最新文章
第08组 Alpha冲刺 (4/6)
第08组 Alpha冲刺 (3/6)
第08组 Alpha冲刺 (2/6)
第08组 Alpha冲刺 (1/6)
第四次作业
share分享
Drak Time Summary、遇到任何问题,找书就可以了
AFNWorking网络工具类的抽取
iOS单例的使用
使用Shares实现第三方登陆
热门文章
发布emoji
例如微博表情添加到textView中
UIScrollView和UIPageControl结合使用
例如微博中的表情选择排布
切换系统自带键盘为自定义键盘
Python基础入门第1天整理
新建Scrapy项目
Python虚拟环境的安装
Python正则表达式
python装饰器
Copyright © 2011-2022 走看看