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

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 ABCDXYZ @ 2017-05-30 09:09:56

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a[1000];
int main( ){
    int b,c=0,i;
    for(i=1;i<=10;i++)
        cin>>a[i];
    cin>>b;
    for(i=1;i<=10;i++){
        if(a[i]<=30+b)
        c=c+1;
    }
    printf("%d",c);
return 0;
}
代码不解释,话说你的“错误,请重输数据: ”是干嘛的

by 引领天下 @ 2017-05-30 10:34:44

#include <cstdio>
int main(void){
    int a[10],h,ans=0;
    for (int i=0;i<10;i++)scanf ("%d",&a[i]);
    scanf ("%d",&h);
    h+=30;
    for (int i=0;i<10;i++)ans+=h>=a[i];
    printf ("%d",ans);
}

by HigHwind @ 2017-06-07 14:46:05

不用考虑数据输入错误,是机器judge,不是人工judge-。-

不用管交互


by zty52 @ 2017-06-09 21:51:38

#include<stdio.h>
int main()
{int a[11],i,s,z=0;
for(i=1;i<=10;i++)
scanf("%d",&a[i]);
scanf("%d",&s);
for(i=1;i<=10;i++)
if(s+30>=a[i])z++;
printf("%d",z);
return 0;
}

by SasukeUchiha @ 2017-06-11 11:27:03

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

by 189279378w @ 2017-06-11 19:21:34

#include <iostream> 
using namespace std;
int a[11];
int hei, ans;
int main () {
    for (int i = 0; i < 10; i++) cin>>a[i];
    cin>>hei;
    for (int i = 0; i < 10; i++) {
        if (a[i] <= (hei + 30)) ans++;
    }
    cout<<ans;
    return 0;
}

by EricZeng @ 2017-06-18 15:06:32

var a,b,c,d,e,v,w,x,y,z,ans,n:longint;
begin
  readln(a,b,c,d,e,v,w,x,y,z);
  readln(n);
  ans:=0;
  if n+30>=a then inc(ans);
  if n+30>=b then inc(ans);
  if n+30>=c then inc(ans);
  if n+30>=d then inc(ans);
  if n+30>=e then inc(ans);
  if n+30>=v then inc(ans);
  if n+30>=w then inc(ans);
  if n+30>=x then inc(ans);
  if n+30>=y then inc(ans);
  if n+30>=z then inc(ans);
  writeln(ans);
end.

by akmld2002 @ 2017-06-25 20:43:11

#include<iostream>
using namespace std;
int a[10];
int main(){
    int i,h,h_,count=0;
    for(i=0;i<=9;i++)
        cin>>a[i];
    cin>>h;
    h_=h+30;
    for(i=0;i<=9;i++)
        if(a[i]<=h_)
            count=count+1;
    cout<<count;
    return 0;
}

by Erina @ 2017-07-07 19:33:24

@EricZeng

干嘛?

为什么不用数组?


by EricZeng @ 2017-07-14 15:13:08

@Im_ygy :

用数组不一定好

不用数组也不一定不好


| 下一页