搜索
查看: 466|回复: 1
打印 上一主题 下一主题

12004

[复制链接]
跳转到指定楼层
楼主
发表于 2015-10-12 12:32:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
代码如下。
奖学金
[mw_shl_code=cpp,true]#include <iostream>
  
class student
{
    public:
    int number;
    int chinese;
    int math;
    int english;
    int total;
};
void _tswap(student &a,student &b)
{
    int t;
    t=a.number;a.number=b.number;b.number=t;
    t=a.chinese;a.chinese=b.chinese;b.chinese=t;
    t=a.math;a.math=b.math;b.math=t;
    t=a.english;a.english=b.english;b.english=t;
    t=a.total;a.total=b.total;b.total=t;
      
}
void _tsort(student *p,int count)
{
    int i,j;
    for(int i=0;i<count;i++)
    {
        for(int j=i+1;j<count;j++)
        {
            if( p.total<p[j].total)
            {
                _tswap(p,p[j]);
            }
            else if(p.total == p[j].total)
            {
                if(p.chinese < p[j].chinese)
                {
                    _tswap(p,p[j]);
                }
                else if(p.chinese == p[j].chinese)
                {
                    if(p.number>p[j].number)
                    {
                        _tswap(p,p[j]);
                    }
                }
            }
        }
    }
}
int main(void)
{
    const int zuigao = 5;
    int i;
    int count;
    std::cin >> count;
    student *p = new student[count];
    for(i=0;i<count;i++)
    {
        std::cin >> p.chinese >> p.math >> p.english;
        p.total = p.chinese + p.math + p.english;
        p.number = i+1;
    }
    _tsort(p,count);
    for(i=0;i<zuigao;i++)
    {
        std::cout << p.number << " " << p.total <<std::endl;
    }
    delete []p;
    p=NULL;
    return 0;
}
[/mw_shl_code]
沙发
 楼主| 发表于 2015-10-12 13:09:33 | 只看该作者
自己写的代码
标识符有中文有英文请见谅。。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表