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:
博客園
模板提供:
滬江博客
<
2012年5月
>
日
一
二
三
四
五
六
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 解題報告
這樣的話不是每一次都要重復計算階乘的么?很浪費時間的。。。。
--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)
久久青青国产
|
99久久精品免费观看国产
|
国产毛片久久久久久国产毛片
|
热综合一本伊人久久精品
|
久久99亚洲综合精品首页
|
亚洲国产精品无码久久久久久曰
|
精品人妻伦九区久久AAA片69
|
国内精品久久人妻互换
|
亚洲精品97久久中文字幕无码
|
久久久噜噜噜久久中文字幕色伊伊
|
99久久国产宗和精品1上映
|
亚洲精品无码久久久
|
国产精品禁18久久久夂久
|
少妇人妻综合久久中文字幕
|
久久天天躁狠狠躁夜夜2020老熟妇
|
精品综合久久久久久88小说
|
性欧美大战久久久久久久久
|
狠狠色丁香婷婷久久综合五月
|
国产日韩欧美久久
|
亚洲国产一成人久久精品
|
精品久久久久中文字
|
久久精品人人做人人爽电影蜜月
|
狠狠综合久久综合88亚洲
|
国产精品无码久久综合网
|
亚洲AV日韩精品久久久久
|
女人高潮久久久叫人喷水
|
日日狠狠久久偷偷色综合0
|
91精品国产乱码久久久久久
|
国产激情久久久久影院老熟女
|
色欲综合久久中文字幕网
|
久久国内免费视频
|
青青久久精品国产免费看
|
久久国产综合精品五月天
|
无码精品久久一区二区三区
|
国产亚洲精久久久久久无码AV
|
国产91色综合久久免费
|
国产午夜免费高清久久影院
|
久久综合给久久狠狠97色
|
精品国产一区二区三区久久久狼
|
亚洲午夜久久久久久久久电影网
|
国产精品免费看久久久
|