NBUT1639大还是小?(细节)

输入两个实数,判断第一个数大,第二个数大还是一样大。每个数的格式为: [整数部分].[小数部分]

简单起见,整数部分和小数部分都保证非空,且整数部分不会有前导 0。不过,小数部分的最 后可以有 0,因此 0.0 0.000 是一样大的。

Input
输入包含不超过 20 组数据。每组数据包含一行,有两个实数(格式如前所述)。每个实数都 包含不超过 100 个字符。
Output
对于每组数据,如果第一个数大,输出"Bigger"。如果第一个数小,输出"Smaller"。如果两个 数相同,输出"Same"。
Sample Input
1.0 2.0
0.00001 0.00000
0.0 0.000
Sample Output
Case 1: Smaller
Case 2: Bigger
Case 3: Same


注意细节就好,整数先判断,相同的话再一直判断到有不同为止,还没有出结果就判断到两字符串结束,若还是没有结果,那就是same了

代码


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    char s1[105],s2[105];
    int cas=1;
    int n1,n2,temp;
    while(~scanf("%s%s",s1,s2))
    {
        if(s1[0]>s2[0])
            printf("Case %d: Bigger\n",cas++);
        else if(s1[0]<s2[0])
            printf("Case %d: Smaller\n",cas++);
        else
        {
            bool label;
            bool finish=false;
            n1=strlen(s1);
            n2=strlen(s2);
            temp=min(n1,n2);
            for(int i=0;i<temp;i++)
                if(s1[i]!=s2[i])
                {
                    finish=true;
                    if(s1[i]<s2[i])
                        label=false;
                    else
                        label=true;
                    break;
                }
            if(!finish&&n1!=n2)
            {
                if(n1>n2)
                {
                    for(int i=temp;i<n1;i++)
                        if(s1[i]-'0'>0)
                    {
                        finish=true;
                        label=true;
                        break;
                    }
                }
                else
                {
                    for(int i=temp;i<n2;i++)
                        if(s2[i]-'0'>0)
                    {
                        finish=true;
                        label=false;
                        break;
                    }
                }
            }
            if(finish)
            {
                if(label)
                printf("Case %d: Bigger\n",cas++);
                else
                printf("Case %d: Smaller\n",cas++);
            }
            else
                printf("Case %d: Same\n",cas++);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值