OJ:一个output-limit-exceed的原因

最近又开始写一些oj,主要还是想应对机试。其他且不论,今天遇到的这个问题先记录一下,日后在分析。

原本代码

#include<stdio.h>
#include<math.h>

int main(){
    int x,y;
    while(scanf("%d%d",&x,&y)){
        if(x>y){
            int temp = x;
            x = y;
            y = temp;
        }

    double k = (1+sqrt(5))/2;

    int a = y-x;
    if(x==(int)(k*a))
            printf("0
");
    else printf("1
");
    }

    return 0;
}

ac代码

#include<iostream>
#include<cmath>
using namespace std;

int main(){
    int x,y;
    while(cin>>x>>y){
        if(x>y){
            int temp = x;
            x = y;
            y = temp;
        }

    float k = (1+sqrt(5))/2;

    int a = y-x;
    if(x==(int)(k*a))printf("0
");
    else printf("1
");

    }

    return 0;
}



查找原因是

scanf不判断是否读到EOF


while(cin>>n)没有问题

while(scanf("%d",&n)!=EOF)没有问题

while(scanf("%d",&n))产生output limit exceed

原文地址:https://www.cnblogs.com/JK-Z/p/12264746.html