top1编程
← 返回题目
题解

【入门】象棋大赛

2 条题解

  • 0
    @ 2026-10-24 6:19:44

    1. 解题思路

    按年龄从高到低判断:15岁及以上为青年组,11岁及以上为少年组,其余为儿童组。题目保证年龄在8到30之间,不需要处理范围外输入。

    2. 坑点和注意事项

    少年组覆盖11到14岁,不能把下界误写为14岁。15岁归青年组、11岁归少年组、8到10岁归儿童组;输出使用题目指定的小写拼音。

    3. 复杂度

    • 时间复杂度:O(1),最多比较两个年龄分界。
    • 空间复杂度:O(1),只保存年龄。
    /*
    思路:按15岁和11岁两个分界线,从高到低确定参赛组别。
    关键:11到14岁都是少年组,不能将下界误写为14岁。
    坑点:15岁归青年组,11岁归少年组,8到10岁归儿童组。
    时间复杂度:O(1)。
    空间复杂度:O(1);年龄在8到30之间,使用int。
    */
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        if (n >= 15)
        {
            cout << "qingnianzu" << endl;
        }
        else if (n >= 11)
        {
            cout << "shaonianzu" << endl;
        }
        else
        {
            // 题目保证至少8岁,剩余年龄都属于儿童组。
            cout << "ertongzu" << endl;
        }
        return 0;
    }
    
    • 0
      @ 2026-7-28 22:09:45
      #include <bits/stdc++.h>
      using namespace std;
      int main(){
      	int n;
      	cin>>n;
      	if(n >= 15){
      		cout<<"qingnianzu";
      	}else if(n >= 14){
      		cout<<"shaonianzu";
      	}else if(n >= 8){
      		cout<<"ertongzu";
      	}
      }
      
      • 1