2019年湘潭大学程序设计竞赛(重现赛)A ——Who's better?

原代码: (通过率为100%)

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
struct team
{  int n;
   int p;
   int s;   
};
struct team  t1,t2;
int main()
{
    cin>>t1.n>>t1.p>>t1.s;
    cin>>t2.n>>t2.p>>t2.s;
    if(t1.n<t2.n)
    {
        cout<<'2'<<endl;
    }
    else if(t1.n>t2.n)
    { 
        cout<<'1'<<endl;   
    }
    else{
            if(t1.p<t2.p)
        {
            cout<<'1'<<endl;
        }
        else if(t1.p>t2.p)
        { 
            cout<<'2'<<endl;   
        }
        else{
                if(t1.s<t2.s)
            {
                cout<<'1'<<endl;
            }
            else if(t1.s>t2.s)
            { 
                cout<<'2'<<endl;   
            }
            else
            {
                cout<<"God"<<endl;
            }
            
        }
        
    }
    return 0;
}

以下关于结构体内容来自:c.biancheng.net/view/2031.html    

理论上讲结构体的各个成员在内存中是连续存储的,和数组非常类似,例如上面的结构体变量 stu1、stu2 的内存分布如下图所示,共占用 4+4+4+1+4 = 17 个字节。

需要注意的是,结构体是一种自定义的数据类型,是创建变量的模板,不占用内存空间;结构体变量才包含了实实在在的数据,需要内存空间来存储。

 

 

通过率为100%代码:

基本知识点:用sort(含定义cmp子函数)排序比较结构体大小

#include<iostream>
using namespace std;
#include<string>
#include<cmath>
#include<cstdio>
#include<cstring> 
#include<algorithm>
#include<vector>
#define minx 1e18;
#define maxx 0;
typedef long long ll; 
 
struct st{
    int n,p,s;
    int d;
};
st stu[2];
int cmp(st a,st b)
{
    if(a.n!=b.n)return a.n>b.n;
    else if(a.p!=b.p)return a.p<b.p;
    else return a.s<b.s;
}
int main()
{
    stu[0].d=1;
    stu[1].d=2;
    cin>>stu[0].n>>stu[0].p>>stu[0].s;
    cin>>stu[1].n>>stu[1].p>>stu[1].s;
    sort(stu,stu+2,cmp);
    if(stu[0].n==stu[1].n&&stu[0].p==stu[1].p&&stu[0].s==stu[1].s)
    {
        cout<<"God"<<endl;
    }else{
        cout<<stu[0].d<<endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值