首页 > 其他分享 >The long way to arrive the other shore

The long way to arrive the other shore

时间:2024-10-01 12:20:24浏览次数:5  
标签:main int scanf long 1000001 include shore other arrive

题目

起初(以为会顺利)

#include<stdio.h>
int main()
{
    int N,k,i;
    int a[N];
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    scanf("%d",&k);
    for(i=0;i<N;i++)
    {
        if(a[i]!=k)
        {
            printf("%d ",a[i]);
        }

    }     
    return 0;
}

Runtime error makes me failed(so many times)然后(发现N的输入问题)

#include<stdio.h>
int main()
{
    int N,k,i;
    scanf("%d",&N);
    int a[N];
    
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    scanf("%d",&k);
    for(i=0;i<N;i++)
    {
        if(a[i]!=k)
        {
            printf("%d ",a[i]);
        }

    }     
    return 0;
}

but failed again还未结束,尝试将数组开外边,扩大容量

#include<stdio.h>
int a[1000001];
int main()
{
    int N,k,i;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    scanf("%d",&k);
    for(i=0;i<N;i++)
    {
        if(a[i]!=k)
        {
            printf("%d ",a[i]);
        }

    }     
    return 0;
}

but he still didn't let me pass终于(把全部int换成了long long以求万无一失)

#include<stdio.h>
long long a[1000001];
int main()
{
    long long N,k,i;
    scanf("%lld",&N);
    for(i=0;i<N;i++)
    {
        scanf("%lld",&a[i]);
    }
    scanf("%lld",&k);
    for(i=0;i<N;i++)
    {
        if(a[i]!=k)
        {
            printf("%lld ",a[i]);
        }

    }     
    return 0;
}

Victory

坎坷人生路也便是如此,一步一个脚印地试错吧,只要肯付出时间精力,那便无所悔憾吧?!

标签:main,int,scanf,long,1000001,include,shore,other,arrive
From: https://blog.csdn.net/Z618816168/article/details/142669626

相关文章