C++心路歷程
C++博客
首頁
新隨筆
新文章
聯(lián)系
聚合
管理
posts - 33, comments - 25, trackbacks - 0
ZOJ 1210 解題報告
大浮點數(shù)運算.
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
肖羽思
閱讀(502)
評論(2)
編輯
收藏
引用
所屬分類:
ZOJ
FeedBack:
#
re: ZOJ 1210 解題報告
2009-04-03 09:00 |
Ard
能發(fā)一下你的...頭文件...不是這樣一來我看不懂.....我剛剛來這博客的.....想學好一點C++ 為后面學習JAVA打下良好的基礎(chǔ)!
回復(fù)
更多評論
#
re: ZOJ 1210 解題報告
2009-04-03 10:46 |
肖羽思
頭文件見我另一篇隨筆:
http://m.shnenglu.com/Yusi-Xiao/archive/2009/03/26/77988.aspx
@Ard
回復(fù)
更多評論
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
【推薦】100%開源!大型工業(yè)跨平臺軟件C++源碼提供,建模,組態(tài)!
相關(guān)文章:
ZOJ 1813 解題報告
ZOJ 1406 解題報告
ZOJ 1350 解題報告
ZOJ 1249 解題思路
ZOJ 1151 解題報告
ZOJ 1113 解題報告
ZOJ 1059 解題報告
ZOJ 1057 解題報告
ZOJ 1210 解題報告
ZOJ 1160 解題報告
網(wǎng)站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
Copyright ©2025 肖羽思 Powered by:
博客園
模板提供:
滬江博客
<
2025年7月
>
日
一
二
三
四
五
六
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
8
9
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
(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 解題報告
這樣的話不是每一次都要重復(fù)計算階乘的么?很浪費時間的。。。。
--WayneWu
5.?re: POJ 2965 解題報告
@Tanky Woo
你說的不對,你根本沒看樓主的算法,結(jié)果必定為1
--劉灝
閱讀排行榜
1.?POJ 1753 解題報告(5067)
2.?POJ 2965 解題報告(3746)
3.?ZOJ 1204 解題報告(2157)
4.?ZOJ 1004 解題報告(1916)
5.?ZOJ 1091 解題報告(1341)
評論排行榜
1.?POJ 1753 解題報告(8)
2.?POJ 2965 解題報告(8)
3.?ZOJ 1004 解題報告(2)
4.?ZOJ 1210 解題報告(2)
5.?ZOJ 1525 解題報告(1)
久久久久久无码国产精品中文字幕
|
Xx性欧美肥妇精品久久久久久
|
中文字幕久久久久人妻
|
久久人人爽人人爽人人片AV东京热
|
欧美久久综合性欧美
|
精品一区二区久久久久久久网站
|
国内精品人妻无码久久久影院
|
久久这里只有精品久久
|
国产精品18久久久久久vr
|
国产精品久久自在自线观看
|
久久亚洲精品成人av无码网站
|
麻豆亚洲AV永久无码精品久久
|
久久w5ww成w人免费
|
久久大香香蕉国产
|
国产L精品国产亚洲区久久
|
久久久久久A亚洲欧洲AV冫
|
午夜精品久久久久成人
|
国内精品久久久久影院网站
|
精品一二三区久久aaa片
|
亚洲精品乱码久久久久久不卡
|
国产一区二区久久久
|
婷婷久久久亚洲欧洲日产国码AV
|
日韩人妻无码一区二区三区久久
|
国产精品久久久久国产A级
|
国产精品美女久久久网AV
|
日日狠狠久久偷偷色综合免费
|
精品熟女少妇a∨免费久久
|
欧美伊香蕉久久综合类网站
|
久久精品二区
|
无码专区久久综合久中文字幕
|
国产精品欧美亚洲韩国日本久久
|
久久精品国产亚洲Aⅴ蜜臀色欲
|
狠狠久久综合伊人不卡
|
亚洲色大成网站www久久九
|
国产午夜精品理论片久久
|
精品无码久久久久国产动漫3d
|
91亚洲国产成人久久精品网址
|
精品国产乱码久久久久久人妻
|
久久www免费人成看国产片
|
国产午夜免费高清久久影院
|
亚洲精品97久久中文字幕无码
|