| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 631 人关注过本帖
标题:NKOJ 1021: hard for me to debug. Where is it?
取消只看楼主 加入收藏
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
 问题点数:0 回复次数:2 
NKOJ 1021: hard for me to debug. Where is it?

For the following GNU C code, I got 9AC + 1WA. I thought my algorithm is correct and there must be some bug in my code.

Could we de"bug"?

程序代码:

#include <stdio.h>

long long b[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489, 1162261467, 3486784401, 10460353203, 31381059609, 94143178827, 282429536481, 847288609443, 2541865828329, 7625597484987, 22876792454961, 68630377364883, 205891132094649, 617673396283947};

int main()
{
unsigned n;
int k;

while( scanf(\"%d\", &n) != -1 )
{
if(n==1)
{
printf(\"\n\");
continue;
}

--n;
k=0;

while(n)
{
if(n&1)
printf(\"%lld\n\", b[k]);

++k;
n >>= 1;
}
}

return 0;
}

搜索更多相关主题的帖子: NKOJ Where debug hard 
2007-07-23 22:38
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 

Do you mean the bug is

scanf("%d", &n)

?



I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-07-24 03:54
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
以下是引用leeco在2007-7-24 2:44:52的发言:
这么好一算法毁在一%d手里了

got it, leeco. You saved my life.

In Tan, Haoqiang's book, there is no %u option for scanf(). But why is

scanf(\"%u\", &n);

now allowed?


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-07-24 04:17
快速回复:NKOJ 1021: hard for me to debug. Where is it?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026047 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved