F - Comparison of Android versions (模拟)

版本号码比较。读懂题意很简单。

这里写图片描述

1、比较两个字符串的第一个字母的大小.
2、如果两个字符串的第二个字母不同就比较接下来的三个字母的大小.
如果两个字符串的第二个字母相同就比较剩余的四个字母.

#include<iostream>
#include<string.h>
#define maxn 10010
using namespace std;
char s[maxn],ss[maxn];
int main(){
    int T,times=1;
    cin>>T;
    getchar();
    while(T--){
        cin>>s>>ss;
        cout<<"Case "<<times++<<':';
        char tmp1[4]={0},tmp2[4]={0};
        tmp1[0]=s[0];
        tmp2[0]=ss[0];
        //先比较首字母的大小并输出
        if(strcmp(tmp1,tmp2)>0) cout<<" > ";
        else if(strcmp(tmp1,tmp2)<0) cout<<" < ";
        else cout<<" = ";

        //再比较接下来的第二个字母
        tmp1[0]=s[1];
        tmp2[0]=ss[1];
        //第二个字母不同,比较接下来三个字母
        if(strcmp(tmp1,tmp2)!=0) {
            s[5]=0;ss[5]=0;
            if(strcmp(s+2,ss+2)>0)
                cout<<'>'<<endl;
            else if(strcmp(s+2,ss+2)<0)
                cout<<'<'<<endl;
            else
                cout<<'='<<endl;
        }
        else{
            if(strcmp(s+2,ss+2)>0)
                cout<<'>'<<endl;
            else if(strcmp(s+2,ss+2)<0)
                cout<<'<'<<endl;
            else
                cout<<'='<<endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值