top1编程
← 返回题目
题解

【入门】小高考1

2 条题解

  • 0
    @ 2026-10-24 6:30:45

    1. 解题思路

    先统计四门成绩中至少90分的门数s,再按门数输出等级:4门为A,2或3门为B,1门为C,0门为D。

    2. 坑点和注意事项

    90分本身计入达标门数,不能使用严格大于。先判断s=4,再判断s≥2,才能把A和B分开;输入恰好四门成绩,输出大写等级字母。

    3. 复杂度

    • 时间复杂度:O(1),固定处理四门成绩。
    • 空间复杂度:O(1),只保存当前成绩及达标门数。
    /*
    思路:统计四门成绩中达到90分的门数,再按门数确定等级。
    关键:四门为A,二三门为B,一门为C,零门为D。
    坑点:恰好90分也算达到要求,不能使用严格大于。
    时间复杂度:O(1),固定读取四门成绩。
    空间复杂度:O(1);成绩和门数使用int。
    */
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int x, s = 0;
        for (int i = 0; i < 4; i++)
        {
            cin >> x;
            if (x >= 90)
            {
                s++;
            }
        }
        // 从高等级开始判断,二门和三门合并在同一分支。
        if (s == 4)
        {
            cout << "A" << endl;
        }
        else if (s >= 2)
        {
            cout << "B" << endl;
        }
        else if (s == 1)
        {
            cout << "C" << endl;
        }
        else
        {
            cout << "D" << endl;
        }
        return 0;
    }
    
    • 0
      @ 2026-7-28 22:09:49
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int a,b,c,d,s=0;
      	cin>>a>>b>>c>>d;
      	if(a>=90) s=s+1;
      	if(b>=90) s=s+1;
      	if(c>=90) s=s+1;
      	if(d>=90) s=s+1;
      	if(s==4) cout<<"A";
      	else if(s>=2) cout<<"B";
      	else if(s==1) cout<<"C";
      	else cout<<"D";
          return 0;
      }
      
      • 1