NYOJ73比大小

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=73


每种情况不要落下就好了。

#include <cstdio>
#include <cstring>

char s[1005];
char s1[1005];
int len_s,len_s1;

bool isEnd()

{
    len_s = strlen(s);
    len_s1 = strlen(s1);
    if(len_s == 1 && len_s1 == 1 && s[0] == '0' && s1[0] == '0')
        return true;
    return false;
}

bool isZero()

{
    int f = 1;
    int f1 = 1;
    for(int i = 0; i < len_s; ++i)
        if(s[i] != '-' && s[i] != '0')
        {
            f = 0;
            break;
        }
    for(int i = 0; i < len_s1; ++i)
        if(s1[i] != '-' && s1[i] != '0')
        {
            f1 = 0;
            break;
        }
    if(f && f1)
        return true;
    else
        return false;
}
int main()

{
    while(~scanf("%s%s",s,s1))
    {
        if(isEnd())
            break;
        if(strcmp(s,s1) == 0 || isZero())
            printf("a==b\n");
        else if(s[0] == '-' && s1[0] != '-')
            printf("a<b\n");
        else if(s[0] != '-' && s1[0] == '-')
            printf("a>b\n");
        else if(s[0] != '-' && s1[0] != '-')
        {
            if(len_s > len_s1)
                printf("a>b\n");
            else if(len_s < len_s1)
                printf("a<b\n");
            else
            {
                int i;
                for(i = 0;i < len_s;++i)
                {
                    if(s[i] > s1[i])
                    {
                        printf("a>b\n");
                        break;
                    }
                    else if(s[i] < s1[i])
                    {
                        printf("a<b\n");
                        break;
                    }
                }
                if(i == len_s)
                    printf("a==b\n");
            }
        }
        else if(s[0] == '-' && s1[0] == '-')
        {
            if(len_s > len_s1)
                printf("a<b\n");
            else if(len_s < len_s1)
                printf("a>b\n");
            else
            {
                int i ;
                for(int i = 1;i < len_s;++i)
                {
                    if(s[i] > s1[i])
                    {
                        printf("a<b\n");
                        break;
                    }
                    else if(s[i] < s1[i])
                    {
                        printf("a>b\n");
                        break;
                    }
                }
                if(i == len_s)
                    printf("a==b\n");
            }
        }
    }
    return 0;
}

你可能感兴趣的:(模拟,ACM,大数)