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年3月
>
日
一
二
三
四
五
六
22
23
24
25
26
27
28
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
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
(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 解題報告(5049)
2.?POJ 2965 解題報告(3739)
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)
久久亚洲精品无码播放
|
国产精品久久久久久久久久影院
|
久久精品人人做人人爽电影蜜月
|
亚洲av伊人久久综合密臀性色
|
亚洲伊人久久大香线蕉综合图片
|
奇米综合四色77777久久
|
91精品国产综合久久婷婷
|
伊人色综合久久天天
|
日日狠狠久久偷偷色综合0
|
久久亚洲国产精品成人AV秋霞
|
人妻无码αv中文字幕久久
|
国产日产久久高清欧美一区
|
精品久久久久久无码中文野结衣
|
亚洲精品第一综合99久久
|
久久久久亚洲精品天堂
|
国产精品xxxx国产喷水亚洲国产精品无码久久一区
|
久久久无码精品亚洲日韩软件
|
久久久久久亚洲精品不卡
|
久久人妻少妇嫩草AV蜜桃
|
久久91精品国产91久久小草
|
人妻精品久久久久中文字幕
|
亚洲精品国精品久久99热一
|
91精品国产高清久久久久久91
|
久久艹国产
|
婷婷五月深深久久精品
|
久久国产视屏
|
精品久久久久久亚洲精品
|
日本加勒比久久精品
|
久久se精品一区精品二区
|
久久人做人爽一区二区三区
|
99久久精品国产一区二区蜜芽
|
亚洲精品国产字幕久久不卡
|
久久久久97国产精华液好用吗
|
久久发布国产伦子伦精品
|
四虎久久影院
|
精品国产综合区久久久久久
|
国内精品久久久久影院一蜜桃
|
亚洲综合久久夜AV
|
国产成人综合久久久久久
|
久久综合给合久久狠狠狠97色
|
狠狠色丁香久久婷婷综合五月
|