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;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 房地产市场信息系统技术规范目 录1 总则2 术语和代号2.1 术语2.2代号3 基本规定3.1 系...
    Mococo阅读 1,692评论 0 8
  • 聚首是种默契 不要说生生死死终身相依 属于我们的相思 本来就那么一缕 回首以往的岁月 是对是错只代表过去 问津未来...
    朝阳书简阅读 274评论 1 5
  • 前面文章说了要一个好的健身效果,好的睡眠至关重要,如果睡眠不好,会影响到我们的日常生活跟精力,对于那些每天健身的人...
    林几点阅读 513评论 2 1
  • 马刺在今天以111-86大胜太阳,赛后,马刺主教练格雷格-波波维奇接受了采访。 谈及这场胜利,波波维奇说道:“好吧...
    Sandy体育风云阅读 77评论 0 0
  • 在最好的时光,我选择独自一人去远方流浪 这里没有欧式风格 只有砖头砌起的房子 一条有故事的街 一群有故事的人 一间...
    云中的喵阅读 296评论 0 1