2010北京市小学生程序设计友谊赛详细答案

第1题

#include <iostream>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}

第2题

分析:
以下面的数据为例:

3 
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3

对应关系:

班级编号总力量
1班5
2班10
3班15

按总力量排序后

班级编号总力量
3班15
2班10
1班5

1班,位于第3行,所以是第3名;2班位于第2行,所以是第2名;3班,位于第1行,所以是第1名。输出结果为3 2 1。

#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a, b, c, d, e;
    int total[11], classNo[11];//总力量和班级编号
    for(int i = 1; i <= n; i++)
    {
        cin >> a >> b >> c >> d >> e;
        total[i] = a + b + c + d + e;
        classNo[i] = i;
    }

    for(int i = 1; i < n; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            if(total[i] < total[j])
            {
                swap(total[i], total[j]);
                swap(classNo[i], classNo[j]);
            }
        }
    }

    for(int cls = 1; cls <= n; cls++)
    {
        for(int row = 1; row <= n; row++)
        {
            //第row行的班级编程是cls
            if(classNo[row] == cls)
            {
                cout << row << ' ';
            }
        }
    }
    cout << endl;

    return 0;
}

第3题

#include <iostream>
using namespace std;

int main()
{
    string s[10], t;
    string tmp;
    int pos = 0;

    do
    {
        cin >> tmp;
        s[pos] = tmp;
        pos++;
    }while('.' != tmp[tmp.size() - 1]);

    cin >> t;
    int cnt = 0;
    for(int i = 0; i < pos; i++)
    {
        if(t ==s[i])
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

咨询信奥课或加微信群,请加微信307591841或QQ307591841

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值