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
;
}
查看全文
相关阅读:
HihoCoder#1513 : 小Hi的烦恼(五维数点 bitset 分块)
cf914F. Substrings in a String(bitset 字符串匹配)
BZOJ4503: 两个串(bitset字符串匹配)
HDU5972Regular Number(ShiftAnd算法 bitset)
BZOJ1563: [NOI2009]诗人小G(决策单调性 前缀和 dp)
cf868F. Yet Another Minimization Problem(决策单调性 分治dp)
BZOJ4709: [Jsoi2011]柠檬(决策单调性)
cf633F. The Chocolate Spree(树形dp)
BZOJ1044: [HAOI2008]木棍分割(dp 单调队列)
2、RenderScript的计算(2013.05.07)
原文地址:https://www.cnblogs.com/Knuth/p/1575672.html
最新文章
GIT入门笔记(15)- 链接到私有GitLab仓库
工作环境总结(2)业务培训
eclipse版本对应的jdk版本
工作环境总结(1)开发环境搭建
GIT入门笔记(14)- 链接到远程仓库
GIT入门笔记(12)- 删除文件、提交删除和恢复删除
GIT入门笔记(11)- 多种撤销修改场景和对策--实战练习
GIT入门笔记(10)- 多种撤销修改场景和对策
GIT入门笔记(9)- git的add和commit机制原理
GIT入门笔记(8)-- 查看历史提交记录/根据版本号回到过去或未来
热门文章
GIT入门笔记(7)- 修改文件并向版本库提交
GIT入门笔记(6)- 向版本库添加文本文件
GIT入门笔记(5)- 创建版本库
GIT入门笔记(4)- GIT 安装
GIT入门笔记(3)- git中的一些概念和原理
GIT入门笔记(2)- 典型的工作模式
GIT入门笔记(1)- Git的基本概念
maven阿里云中央仓库
eclipse+Maven插件报错:-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
HihoCoder#1509 : 异或排序(二进制)
Copyright © 2011-2022 走看看