top1编程
← 返回题目
题解

【基础】奖学金

1 条题解

  • 0
    @ 2026-7-29 0:18:35
    #include<bits/stdc++.h>
    using namespace std;
    //426. 【入门】奖学金评级
    int main(){
    	int n,a[16];
    	cin>>n;
    	//第一件事 判断这些科目中有没有不及格的科目
    	//第二件事 找出他有多少门优秀的科目
    	int p=1,cnt=0;
    	//p等于1 表示没有不及格的科目 等于0的时候 表示有不及格的科目
    	//cnt用来统计优秀的科目
    	for(int i=1;i<=n;i++){
    		cin>>a[i];
    		if(a[i]<60){//如果存在不及格的科目 那么p更新为0
    			p=0;
    		}
    		if(a[i]>=90){//遇到优秀的科目 cnt次数加1
    			cnt++;
    		}
    	}
    	if(p==0){//当存在不及格 直接输出no
    		cout<<"no";
    	}
    	else{
    		if(cnt>=5){//如果优秀的科目数大于等于5 直接输出1
    			cout<<1;
    		}
    		else if(cnt==3||cnt==4){//3或者4 输出2
    			cout<<2;
    		}
    		else if(cnt==2){//只有两个 则输出3
    			cout<<3;
    		}
    		else{//其他输出no
    			cout<<"no";
    		}
    	}
    	return 0;
    }
    
    • 1