算法与程序--游戏与玩乐
一个新程序员在计算技术上的学习经验
C++博客
|
首页
|
发新随笔
|
发新文章
|
联系
|
聚合
|
管理
随笔:142 文章:0 评论:37 引用:0
pku-1131
一个进制转换的问题,使用了大数的运算。地址:
http://acm.pku.edu.cn/JudgeOnline/problem?id=1131
#include
"
stdio.h
"
#include
"
string.h
"
int
myDivide(
int
*
a,
int
len)
{
int
i
=
0
;
int
residue
=
0
;
int
temp
=
0
;
int
next
=
0
;
for
(i
=
0
; i
<
len; i
++
)
{
temp
=
a[i]
+
next;
a[i]
=
temp
/
8
;
residue
=
temp
%
8
;
next
=
residue
*
10
;
}
while
(next)
{
a[i
++
]
=
next
/
8
;
next
%=
8
;
next
*=
10
;
}
return
i;
}
void
main()
{
int
i
=
0
;
char
str[
1000
];
int
a[
3000
];
int
len
=
0
;
int
len_a
=
0
;
while
(scanf(
"
%s
"
,str)
!=
EOF)
{
len
=
strlen(str);
for
(i
=
0
; i
<
len; i
++
)
if
(str[i]
!=
'
0
'
&&
i
!=
1
)
break
;
if
(i
==
len)
printf(
"
%s [8] = 0 [10]\n
"
,str);
else
if
(str[
0
]
==
'
1
'
)
printf(
"
%s [8] = 1 [10]\n
"
,str);
else
{
len_a
=
1
;
a[
0
]
=
str[len
-
1
]
-
48
;
for
(i
=
len
-
2
; i
>
0
; i
--
)
{
len_a
=
myDivide(a,len_a);
a[
0
]
=
str[i]
-
48
;
}
printf(
"
%s [8] = 0.
"
,str);
for
(i
=
1
; i
<
len_a; i
++
)
printf(
"
%d
"
,a[i]);
printf(
"
[10]\n
"
);
}
}
}
发表于 2008-03-22 19:39
ghbxx
阅读(215)
评论(0)
编辑
收藏
引用
只有注册用户
登录
后才能发表评论。
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
网站导航:
博客园
IT新闻
BlogJava
博问
Chat2DB
管理
<
2008年3月
>
日
一
二
三
四
五
六
24
25
26
27
28
29
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)
给我留言
查看公开留言
查看私人留言
随笔档案
2009年3月 (1)
2008年12月 (1)
2008年9月 (1)
2008年8月 (6)
2008年7月 (11)
2008年6月 (49)
2008年4月 (40)
2008年3月 (33)
搜索
最新评论
1. re: pku-1811
楼主啊,稍微改一下你的代码咋就错了。不用miller labin直接用费马定理原来的写不是错就超时啊
--re
2. re: pku-1811
hugeint product_mod(hugeint A, hugeint B, hugeint C)
这个函数中, D = (D + D) % C; 应该错了吧。
--re
3. re: pku-1338
牛逼
--CAT
4. re: pku-3159
好复杂啊。。。
--搜咯翻车鱼
5. re: pku-1001(1)
大数模板啊 要是能支持小数就好了 O(∩_∩)O~
--abilitytao
阅读排行榜
1. RFC-1321MD5算法(1499)
2. SCOKS4协议及其改进(1477)
3. RFC1929-SCOKS V5的用户名/密码认证方式(1469)
4. RFC977-网络新闻组协议文档(1455)
5. RFC1928-SCOKS V5协议(1327)
评论排行榜
1. 大家好,这是一个程序和算法荟萃的地方(4)
2. pku-1338(4)
3. pku-1811(3)
4. pku-1723(3)
5. pku-2002(3)