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
肖羽思
閱讀(498)
評論(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:
博客園
模板提供:
滬江博客
<
2009年4月
>
日
一
二
三
四
五
六
29
30
31
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
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 解題報告
這樣的話不是每一次都要重復計算階乘的么?很浪費時間的。。。。
--WayneWu
5.?re: POJ 2965 解題報告
@Tanky Woo
你說的不對,你根本沒看樓主的算法,結果必定為1
--劉灝
閱讀排行榜
1.?POJ 1753 解題報告(5050)
2.?POJ 2965 解題報告(3739)
3.?ZOJ 1204 解題報告(2148)
4.?ZOJ 1004 解題報告(1914)
5.?ZOJ 1091 解題報告(1335)
評論排行榜
1.?POJ 1753 解題報告(8)
2.?POJ 2965 解題報告(8)
3.?ZOJ 1004 解題報告(2)
4.?ZOJ 1210 解題報告(2)
5.?ZOJ 1059 解題報告(1)
奇米综合四色77777久久
|
久久久久高潮毛片免费全部播放
|
情人伊人久久综合亚洲
|
精品国产一区二区三区久久
|
久久99热狠狠色精品一区
|
久久99精品国产麻豆蜜芽
|
伊人久久大香线蕉成人
|
久久久久亚洲AV无码网站
|
国产精品美女久久久久网
|
色成年激情久久综合
|
一级做a爰片久久毛片毛片
|
久久九九精品99国产精品
|
久久久久香蕉视频
|
久久99久久99精品免视看动漫
|
国产成人久久777777
|
91精品国产91久久综合
|
国内精品久久久久久久久电影网
|
国产精品毛片久久久久久久
|
久久久久久A亚洲欧洲AV冫
|
久久久久亚洲精品男人的天堂
|
久久综合狠狠综合久久综合88
|
久久亚洲中文字幕精品一区四
|
久久青青草原综合伊人
|
亚洲va久久久噜噜噜久久狠狠
|
久久国产精品二国产精品
|
久久精品国产亚洲AV影院
|
久久国产成人午夜AV影院
|
97精品依人久久久大香线蕉97
|
国内精品久久久久伊人av
|
人妻少妇久久中文字幕
|
久久亚洲精品成人AV
|
久久久久AV综合网成人
|
欧美伊香蕉久久综合类网站
|
国产精品毛片久久久久久久
|
26uuu久久五月天
|
久久精品亚洲精品国产欧美
|
久久久久久亚洲精品无码
|
亚洲中文字幕无码久久2020
|
久久久久99精品成人片直播
|
久久久精品国产Sm最大网站
|
午夜精品久久久久成人
|