天天看点

【高精度】比较大小比较大小descriptioninputoutputsample_inputsample_output

比较大小

Time Limit 1000ms

Memory Limit 65536K

description

input

output

sample_input

1
2
4
3
5
5
							      

sample_output

-1
1
0
      
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 110

int main()
{
    char a[MAX],b[MAX];
    while(scanf("%s%s",&a,&b)!=EOF)
    {
        int i,j,k,la=strlen(a),lb=strlen(b),temp;
        /*for(i=0;i<la/2;i++)
        {
            temp=a[i];
            a[i]=a[la-1-i];
            a[la-1-i]=temp;
        }
        for(i=0;i<lb/2;i++)
        {
            temp=b[i];
            b[i]=b[lb-1-i];
            b[lb-1-i]=temp;
        }*/
        if(la>lb) printf("1\n");
        else
        {
            if(la<lb) printf("-1\n");
            else
                for(i=0;i<la;i++)
            {
                if(a[i]==b[i])
                {
                    if(i==la-1) printf("0\n");
                    else
                        continue;
                }
                else
                {
                    if(a[i]>b[i])
                    {
                        printf("1\n");
                        break;
                    }
                    else
                    {
                        if(a[i]<b[i])
                        {
                            printf("-1\n");
                            break;
                        }
                    }
                }
            }
        }
    }
    return 0;
}