为什么0分求教大神

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

PerfectJames @ 2018-06-03 21:04:58

include<bits/stdc++.h>

using namespace std; const int N=10005; int a[N]; int main() { int n,m,ans=0; for(int i=1;i<=10;i++) { cin>>a[i]; cin>>n; m=n+30; } for(int i=1;i<=10;i++) { if(a[i]<=m) ans++; } cout<<ans<<endl; return 0; }


by wenzhang @ 2018-06-03 21:09:00

include<stdio.h>

int a[11],s1,i,s;

int main() {

for(i=1;i<=10;i++)scanf("%d",&a[i]);
scanf("%d",&s);
s+=30;
for(i=1;i<=10;i++)if(a[i]<=s)s1++;
printf("%d",s1);
return 0;

}

正解


by PerfectJames @ 2018-06-03 21:15:08

@wenzhang xiexie danwobuyong printf he scanf


by Chloris @ 2018-06-03 21:19:27

@PerfectJames 那您可以加上

ios::sync_with_stdio(false);
让您的cin&cout的速度和scanf&printf相差无几

by PerfectJames @ 2018-06-03 21:22:26

@wenzhang 咱们程序差不多可我的结果却总往10上蹿


by DrBit @ 2018-06-03 21:34:32

cin>>n; m=n+30;应该放在for循环外面吧


by qwqqqqqq @ 2018-06-03 21:41:14

@PerfectJames Dr_BIt说的没错


by PerfectJames @ 2018-06-04 10:22:30

@Dr_BIt 已通过,谢谢


by 琵琶行 @ 2018-06-20 16:31:03

include<iostream>

using namespace std; int apple[11]; int tao,ans; int main() { for(int i=1;i<=10;i++) cin>>apple[i]; cin>>tao; for(int j=1;j<=10;j++) if(tao+30>=apple[j]) ans++;
cout<<ans; return 0; }


|