D. Er Ba Game


题面:模拟题,按照题意讨论即可。
解析与提示
用三目运算符判断输出,更方便debug。
多用函数,思路更清晰。
另外看别人的代码发现可以学习的地方:构造函数设置优先级
把有2和8的设为12,a==b设为11,剩下的返回(a+b)%10;
接下来就只要比较优先级,若是相等还要比较b1,b2;
最后剩下的就都是"tie"。
较为繁琐的代码:

#include<bits/stdc++.h>
using namespace std;
int t;
int a1,b1,a2,b2;
void f(int a1,int b1,int a2,int b2){
    if(a1==a2&&b1==b2) cout<<"tie"<<endl;
    else if(a1==b1&&a2==b2) cout<<((a1>a2)?"first":"second")<<endl;
    else if(a1==2&&b1==8) cout<<"first"<<endl;
    else if(a2==2&&b2==8) cout<<"second"<<endl;
    else if(a1==b1&&a2!=b2) cout<<"first"<<endl;
    else if(a1!=b1&&a2==b2) cout<<"second"<<endl;
    else if(a1!=b1&&a2!=b2&&(a1+b1)%10!=(a2+b2)%10)
    cout<<((((a1+b1)%10)>((a2+b2))%10)?"first":"second")<<endl; 
    else if(a1!=b1&&a2!=b2&&(a1+b1)%10==(a2+b2)%10){
        if(b1==b2) cout<<"tie"<<endl;
        else cout<<((b1>b2)?"first":"second")<<endl;

    }
}
int main(){
    cin>>t;
    while(t--){
    cin>>a1>>b1>>a2>>b2;
    if(a1>b1) swap(a1,b1);
    if(a2>b2) swap(a2,b2);
    f(a1,b1,a2,b2);    

    }
}

别人家的代码
链接说明