2015年海淀区信息学竞赛小学组详细答案

1 成绩统计

#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(a[i] >= 90 && a[i] <= 100)
        {
            cnt1++;
        }
        else if(a[i] >= 80 && a[i] <= 89)
        {
            cnt2++;
        }
        else if(a[i] >= 60 && a[i] <= 79)
        {
            cnt3++;
        }
        else
        {
            cnt4++;
        }
    }

    cout << "You " << cnt1 << endl;
    cout << "Liang " << cnt2 << endl;
    cout << "Zhong " << cnt3 << endl;
    cout << "Cha " << cnt4 << endl;

    return 0;
}

2 打印图形

#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= 2 * n - 1; i++)
    {
        int j = (i > n) ? 2 * n - i : i;
        for(int k = 1; k < j; k++)
        {
            cout << ' ';
        }

        char c;
        for(c = 'A' + j - 1; c < 'A' + n; c++)
        {
            cout << c;
        }
        for(c = c - 2; c >= 'A' + j - 1; c--)
        {
            cout << c;
        }

        cout << endl;
    }

    return 0;
}

3 数值计算

#include<bits/stdc++.h>
using namespace std;

bool isprime(int a)
{
    if(a == 1)
    {
        return false;
    }

    for(int i = 2; i <= sqrt(a); i++)
    {
        if(a % i == 0)
        {
            return false;
        }
    }

    return true;
}

int main()
{
    int l, r, sum = 0;
    cin >> l >> r;
    for(int i = l; i <= r; i++)
    {
        if(isprime(i) && 
           sqrt(i / 100) - (int)sqrt(i / 100) == 0 && 
           sqrt(i % 100) - (int)sqrt(i % 100) == 0)
        {
            cout << i << endl;
            sum++;
        }
    }

    cout << sum << endl;
    return 0;
}
    原文作者:海天一树X
    原文地址: https://www.jianshu.com/p/fa6be1bd654d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞