交大OJ 1240

来源:互联网 发布:比赛计时器软件 编辑:程序博客网 时间:2024/04/29 05:28

Description

Given a fraction m/n, where m and n are both positive integer. As you know, we can disassemble it into Finite Simple CF, that is <x0, x1,x2,…, xn > ,where n is limited.

Your job is to express m/n.

 


这题没啥难的,难能可贵的是我 runtime error了8次。。

下面总结下RE的情况:

1、数组开小了,或者越界了。

2、数字超过int类型

3、出现了除 0的情况 (此题就是这么错的!!)


贴下错误代码:

#include<stdio.h>long long a[10005]; int main(){    long long m,n,x,i,t,num;    while(~scanf("%lld%lld",&n,&m))    {        num=0;        while(1)        {            x=n/m;   a[num++]=x;            n=n%m;  // 如果n=4,m=2,那么出现n=0的情况,交换后m=0,然后 x=n/m=n/0,就RE了            t=n;n=m;m=t;            if(n%m==0) {a[num++]=n/m; break;}        }         for(i=0;i<num;i++)            if(i!=num-1) printf("%lld ",a[i]);            else printf("%lld\n",a[i]);    }     return 0;}


原创粉丝点击