肥宅这题真难顶啊。。。

问一下各位大佬这道题有什么恶心的角度和测试用例吗?我的通过率一直是80%,但感觉写的代码已满足题目要求。
附代码:
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
	int T;
	while(cin>>T){
		for(int i=1;i<=T;i++){
			int arr[1000],N;
			cin>>N;
			for(int j=0;j<=N-1;j++){
				cin>>arr[j];
			}
			int n1=0;
			for(int j=0;j<=N-1;j++){
				if(arr[j]%5==0){
				if(arr[j]%2==0){
                    n1+=arr[j]; 
				}
                }
			}
			if(n1!=0) cout<<n1<<' ';
			else cout<<"N ";
			
			int n2=0,num=0;
			for(int j=0;j<=N-1;j++){
				if(arr[j]%5==1){
				n2+=arr[j]*pow(-1,num);
				num++; 
				}
			}
			if(n2!=0) cout<<n2<<' ';
			else cout<<"N ";
			
			int n3=0;
			for(int j=0;j<=N-1;j++){
				if(arr[j]%5==2){
				n3++; 
				}
			}
			if(n3!=0) cout<<n3<<' ';
			else cout<<"N ";
			
			double n4=0,num2=0;
			for(int j=0;j<=N-1;j++){
				if(arr[j]%5==3){
				num2++;
				n4+=arr[j]; 
				}
			}
			if(num2!=0) n4/=num2;
			if(n4!=0) cout<<fixed<<setprecision(1)<<n4<<' ';
			else cout<<"N ";
			
			int n5=-1;
			for(int j=0;j<=N-1;j++){
				if(arr[j]%5==4){
				n5=n5>arr[j]?n5:arr[j]; 
				}
			}
			if(n5!=-1) cout<<n5<<' ';
			else cout<<"N";
			cout<<endl;
		}
	}
	return 0;
} 
谢谢。

全部评论
if(n2!=0) cout<<n2<<' &(5528)#39;;            改为   if(num!=0) cout<<n2<<' &(5528)#39;;   试试。。。。n2有可能和为0
点赞 回复
分享
发布于 2022-02-25 13:33

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务