暖黑色

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
B - 大还是小?
Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format:

Description

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

简单起见,整数部分和小数部分都保证非空,且整数部分不会有前导 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

    好吧.......因为队里刷题我是从前往后刷,所以这道水题先被我看见A了,题意全是中文也没什么可解释的。数字的位数是100字符,所以必须要用字符串来处理了,小数点后面的自动补上0以方便最后判断是否相同,然后小数点前面的谁位数多谁就大,位数一样就从第一个数开始比较,一直比出结果为止。这题输入的格式已经固定好了是“整数部分.小数部分"所以不用担心出现一个没有小数点的数,直接比较就可以了。

    下面代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[105],b[105];

int max(int a,int b)
{
    return a>b?a:b;
}

int main()
{
    int len1,len2;
    int i,j;
    int k=0;
    int d1,d2;
    int t;
    while(scanf("%s",a)!=EOF)
    {
        scanf("%s",b);
        len1=strlen(a);
        len2=strlen(b);
        for(i=len1;i<102;i++)
        {
            a[i]='0';
        }
        for(i=len2;i<102;i++)
        {
            b[i]='0';
        }
        t=0;
        k++;
        d1=len1;
        d2=len2;
        cout<<"Case "<<k<<": ";
        for(i=0;i<len1;i++)
        {
           if(a[i]=='.')
           {
               d1=i;
               break;
           }
        }
        for(i=0;i<len2;i++)
        {
            if(b[i]=='.')
            {
                d2=i;
                break;
            }
        }
        if(d1>d2)
        {
            cout<<"Bigger"<<endl;
            t=2;
        }
        else if(d1<d2)
        {
            cout<<"Smaller"<<endl;
            t=2;
        }
        else
        {
            for(i=0;i<max(len1,len2);i++)
            {
                if(a[i]>b[i])
                {
                    t=1;
                    break;
                }
                else if(a[i]<b[i])
                {
                    t=-1;
                    break;
                }
            }
        }
        if(t==0)
            cout<<"Same"<<endl;
        else if(t==1)
            cout<<"Bigger"<<endl;
        else if(t==-1)
            cout<<"Smaller"<<endl;
    }
    return 0;
}

 

posted on 2016-09-05 23:46  暖黑色  阅读(437)  评论(0编辑  收藏  举报