C++心路歷程
C++博客
首頁
新隨筆
新文章
聯系
聚合
管理
posts - 33, comments - 25, trackbacks - 0
ZOJ 1210 解題報告
大浮點數運算.
Code
1
#include
"
BigInteger.h
"
2
#include
<
iostream
>
3
using
namespace
std;
4
5
class
BigDecimal
6
{
7
private
:
8
BigInteger divide;
9
BigInteger divided;
10
int
digit_count;
11
12
BigInteger Divide()
13
{
14
if
(divide
==
BigInteger(
0
))
15
return
BigInteger(
0
);
16
BigInteger result;
17
18
BigInteger temp(
0
), index(
0
), rest(
0
), zero(
0
);
19
BigInteger TEN(
10
);
20
int
end
=
-
1
;
21
int
start
=
divide.Length()
-
1
;
22
vector
<
int
>
quotients;
23
24
while
(rest
!=
zero
||
start
>
end)
25
{
26
temp
=
rest
*
TEN;
27
digit_count
=
start
>
end
?
digit_count : digit_count
+
1
;
28
temp
=
start
>
end
?
temp
+
BigInteger((
int
)(divide[start])) : temp;
29
if
(start
<=
end
&&
temp
<
divided)
30
{
31
quotients.push_back(
0
);
32
}
33
while
(temp
<
divided)
34
{
35
--
start;
36
temp
=
start
>
end
?
temp
*
TEN
+
BigInteger((
int
)(divide[start])) : temp
*
TEN;
37
digit_count
=
start
>
end
?
digit_count : digit_count
+
1
;
38
if
(start
<=
end
&&
temp
<
divided)
39
{
40
quotients.push_back(
0
);
41
}
42
}
43
int
quotient
=
0
;
44
rest
=
temp;
45
while
(rest
>=
divided)
46
{
47
rest
=
rest
-
divided;
48
++
quotient;
49
}
50
quotients.push_back(quotient);
51
--
start;
52
}
53
54
string
r;
55
vector
<
int
>
::iterator i_end
=
quotients.end();
56
for
(vector
<
int
>
::iterator ite
=
quotients.begin(); ite
!=
i_end;
++
ite)
57
{
58
r
+=
(
char
)((
*
ite)
+
'
0
'
);
59
}
60
return
BigInteger(r);
61
}
62
63
public
:
64
BigDecimal()
65
{
66
digit_count
=
0
;
67
divide
=
0
;
68
divided
=
1
;
69
}
70
71
BigDecimal(BigInteger a, BigInteger b)
72
{
73
digit_count
=
0
;
74
divide
=
a;
75
divided
=
b;
76
}
77
78
friend ostream
&
operator
<<
(ostream
&
os, BigDecimal
&
decimal
)
79
{
80
BigInteger result
=
decimal
.Divide();
81
int
length
=
result.Length();
82
int
copy_digit_count
=
decimal
.digit_count;
83
if
(copy_digit_count
>=
length)
84
os
<<
"
0.
"
;
85
os
<<
result;
86
return
os;
87
}
88
}
;
89
90
int
_tmain(
int
argc, _TCHAR
*
argv[])
91
{
92
BigInteger a(
1
), b;
93
cout
<<
"
Problem 4 by team x
"
<<
endl;
94
while
(cin
>>
b)
95
{
96
cout
<<
endl;
97
cout
<<
"
1 /
"
<<
b
<<
"
=
"
<<
endl;
98
BigDecimal bd
=
BigDecimal(a, b);
99
cout
<<
bd
<<
endl;
100
}
101
cout
<<
"
End of problem 4 by team x
"
<<
endl;
102
return
0
;
103
}
104
105
posted on 2009-03-31 21:28
肖羽思
閱讀(497)
評論(2)
編輯
收藏
引用
所屬分類:
ZOJ
FeedBack:
#
re: ZOJ 1210 解題報告
2009-04-03 09:00 |
Ard
能發一下你的...頭文件...不是這樣一來我看不懂.....我剛剛來這博客的.....想學好一點C++ 為后面學習JAVA打下良好的基礎!
回復
更多評論
#
re: ZOJ 1210 解題報告
2009-04-03 10:46 |
肖羽思
頭文件見我另一篇隨筆:
http://www.shnenglu.com/Yusi-Xiao/archive/2009/03/26/77988.aspx
@Ard
回復
更多評論
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
相關文章:
ZOJ 1813 解題報告
ZOJ 1406 解題報告
ZOJ 1350 解題報告
ZOJ 1249 解題思路
ZOJ 1151 解題報告
ZOJ 1113 解題報告
ZOJ 1059 解題報告
ZOJ 1057 解題報告
ZOJ 1210 解題報告
ZOJ 1160 解題報告
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
Copyright ©2025 肖羽思 Powered by:
博客園
模板提供:
滬江博客
<
2025年5月
>
日
一
二
三
四
五
六
27
28
29
30
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
28
29
30
31
1
2
3
4
5
6
7
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
(3)
給我留言
查看公開留言
查看私人留言
隨筆分類
POJ(4)
ZOJ(29)
隨筆檔案
2009年4月 (10)
2009年3月 (23)
文章分類
POJ(1)
ZOJ(1)
文章檔案
2009年3月 (2)
搜索
最新評論
1.?re: ZOJ 1059 解題報告
讓人
--讓人
2.?re: POJ 1753 解題報告
LZ的位運算計算法果然比我的普通方法快很多啊!!!
感謝分享!!!
--hacker003
3.?re: POJ 1753 解題報告
這算法好像有冗余吧
FlipPiece(6585,0)=6570之后就不用FlipPiece(6570,0)了吧
--yangyh
4.?re: POJ 1517 解題報告
這樣的話不是每一次都要重復計算階乘的么?很浪費時間的。。。。
--WayneWu
5.?re: POJ 2965 解題報告
@Tanky Woo
你說的不對,你根本沒看樓主的算法,結果必定為1
--劉灝
閱讀排行榜
1.?POJ 1753 解題報告(5046)
2.?POJ 2965 解題報告(3738)
3.?ZOJ 1204 解題報告(2147)
4.?ZOJ 1004 解題報告(1913)
5.?ZOJ 1091 解題報告(1334)
評論排行榜
1.?POJ 1753 解題報告(8)
2.?POJ 2965 解題報告(8)
3.?ZOJ 1004 解題報告(2)
4.?ZOJ 1210 解題報告(2)
5.?ZOJ 1059 解題報告(1)
丁香久久婷婷国产午夜视频
|
久久久久久狠狠丁香
|
青草久久久国产线免观
|
久久久这里只有精品加勒比
|
五月丁香综合激情六月久久
|
久久久久中文字幕
|
亚洲国产成人精品女人久久久
|
国产成人综合久久精品红
|
99久久精品日本一区二区免费
|
久久精品无码专区免费
|
无码人妻久久一区二区三区
|
国产精品99久久久久久www
|
欧美亚洲另类久久综合婷婷
|
国产麻豆精品久久一二三
|
婷婷久久综合九色综合绿巨人
|
色婷婷久久综合中文久久蜜桃av
|
久久精品国产只有精品66
|
国内精品九九久久精品
|
99久久伊人精品综合观看
|
久久久久久久女国产乱让韩
|
久久99精品国产自在现线小黄鸭
|
一级女性全黄久久生活片免费
|
9久久9久久精品
|
久久精品夜夜夜夜夜久久
|
欧洲国产伦久久久久久久
|
国产AV影片久久久久久
|
久久久久久久人妻无码中文字幕爆
|
一本久久久久久久
|
婷婷久久久亚洲欧洲日产国码AV
|
中文字幕亚洲综合久久2
|
久久久久亚洲AV无码网站
|
久久国产劲爆AV内射—百度
|
亚洲精品乱码久久久久久不卡
|
国产呻吟久久久久久久92
|
99热成人精品免费久久
|
亚洲午夜久久影院
|
亚洲天堂久久精品
|
99精品伊人久久久大香线蕉
|
99久久精品国产一区二区
|
99久久精品国产一区二区三区
|
久久香蕉一级毛片
|