满分!!求各位大佬帮忙想一个更简单的做法_(:зゝ∠)_

P1046 [NOIP2005 普及组] 陶陶摘苹果

林晓芊AliceGloria @ 2017-05-29 23:06:55

#include<cstdio>
int a[12],h,i,all=0;
int main()
{
    for(i=1;i<=10;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]<100 || a[i]>200)
        {
            printf("%s","错误,请重输数据: ");
            i--; 
        }
    }
    scanf("%d",&h);
    if(h<100 || h>120)
    {
        printf("%s","错误,请重输数据: ");
    }
    for(i=1;i<=10;i++) 
    {
        if(h >= a[i]-30) 
        {
            all+=1;
        }
    }
    printf("%d",all);
}

by gggssepgf @ 2017-07-14 17:56:35

#include<stdio.h>
int main()
{
    int a[15],b,count=0;
    for(int i=0;i<=9;i++)
        scanf("%d",&a[i]);
    scanf("%d",&b);
    for(int i=0;i<=9;i++)
        if(b+30>=a[i])
            count++;
    printf("%d",count);
}
我刚才被题目坑了,加了freopen....

by ezoiHQM @ 2017-08-03 07:40:01

#include<cstdio>
inline int read() {
    int ff=1,ee=0;
    char ss=getchar();
    while ((ss<'0'||ss>'9')&&ss!='-') ss=getchar();
    while ((ss>='0'&&ss<='9')||ss=='-') {
        if (ss=='-') ff=-1;
        else ee=ee*10+ss-'0';
        ss=getchar();
    }
    return ee*ff;
}
int main() {
    int a[11],x,ans=0;
    for(int i=1; i<=10; i++) a[i]=read();
    x=read()+30;
    for(int i=1; i<=10; i++)ans+=(a[i]<=x);
    printf("%d",ans);
    return 0;
}

by 亚·破晓 @ 2017-08-03 14:35:38


by 亚·破晓 @ 2017-08-03 14:36:09


上一页 |