记录详情

Runtime Error

foo.c: In function 'input':
foo.c:9:9: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&num[0][i]);
         ^~~~~~~~~~~~~~~~~~~~~~
foo.c:11:9: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&num[1][i]);
         ^~~~~~~~~~~~~~~~~~~~~~
foo.c: In function 'main':
foo.c:49:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&problem);
     ^~~~~~~~~~~~~~~~~~~~
foo.c:53:9: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&n);
         ^~~~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 2ms 348.0 KiB
#2 Accepted 11ms 700.0 KiB
#3 Runtime Error Segmentation fault 1ms 296.0 KiB

代码

#include <stdio.h>
#include <stdlib.h>
int num[2][1000];

void input(int num[][1000],int n)
{
    int i;
    for(i=0; i<=n; i++)
        scanf("%d",&num[0][i]);
    for(i=0; i<=n; i++)
        scanf("%d",&num[1][i]);
}

int sushu(int p,int q)
{
    if(q==0)
        return p;
    else
        return sushu(q,p%q);
}
void seek(int num[][1000],int n)
{
    int i ,res;
    for(i=n; i>=0; i--)
    {
        if(num[0][i]!=0 && num[1][i]!=0 )
        {
            res = sushu(num[0][i],num[1][i]);
            printf("%d %d\n",num[0][i]/res,num[1][i]/res);
            break;
        }
        else if(num[0][i]==0 && num[1][i]!=0)
        {
            printf("0 1\n");
            break;
        }
        else if(num[0][i]!=0 && num[1][i]==0)
        {
            printf("infty\n");
            break;
        }
        else
            continue;
    }
}
int main()
{
    int problem;
    scanf("%d",&problem);
    int i ,n;
    for(i=1; i<=problem; i++)
    {
        scanf("%d",&n);
        input(num,n);
        seek(num,n);
    }
    return 0;
}

信息

递交者
类型
递交
题目
P1000 hitwh 2019 新生赛 A ∞
语言
C
递交时间
2020-12-21 22:15:37
评测时间
2020-12-21 22:15:37
评测机
分数
60
总耗时
15ms
峰值内存
700.0 KiB