没好好读题,把第一个数当成输入要判定的数了,关键是输出的结果就一个错的
然后就开始找为什么那个错了,一度以为题出错了(lll¬ω¬)
#include <iostream> #include<stdio.h> #include<string> #include<algorithm> #include<math.h> using namespace std; int main() { int num[1000]; int i; cin>>i; //最后发现第一个输入的数是要处理的个数 int n=0; int f1=0,f2=0,f4=0; int a1=0,a2=0,a3=0,a5=0; double a4=0; while(i>0) //赶紧处理 { cin>>num[n]; if(num[n]%5==0&&num[n]%2==0) { f1=1; a1+=num[n]; } if(num[n]%5==1) { if(f2==0) f2=1; else f2*=-1; a2+=f2*num[n]; } if(num[n]%5==2) a3++; if(num[n]%5==3) { f4++; a4+=num[n]; } if(num[n]%5==4) { if(num[n]>a5) a5=num[n]; } n++; i--; } if(f1!=0) cout<<a1<<" "; else cout<<"N "; if(f2!=0) cout<<a2<<" "; else cout<<"N "; if(a3!=0) cout<<a3<<" "; else cout<<"N "; if(f4!=0) printf("%.1f ",a4/f4); else cout<<"N "; if(a5!=0) cout<<a5; else cout<<"N"; return 0; }