Educational Codeforces Round 5 A

Problem A:http://codeforces.com/contest/616/problem/A

A. Comparing Two Long Integers

果然还是我太天真了(长整数比较不就是long long么........于是一直wa on 9,直到今天起床看了看别人的代码才恍然大悟。。。

#include<stdio.h>  
#include<string.h>  
const int MAX_N = 1000005;  
  
int main(){  
    char a[MAX_N],b[MAX_N];  
    int lena,lenb,la,lb,pa=0,pb=0,i;  
    scanf("%s%s",a,b);  
    lena=strlen(a);  
    lenb=strlen(b);  
    while(pa<lena&&a[pa]=='0') pa++;  
    while(pb<lenb&&b[pb]=='0') pb++;  
    la=lena-pa;  
    lb=lenb-pb;  
    if(la>lb)  
    printf(">\n");  
    else if(la<lb)  
    printf("<\n");  
    else{  
        for(i=pa;i<lena;i++){  
            if(a[i]>b[i-pa+pb]){  
            printf(">\n");  
            return 0;  
            }  
            else if(a[i]<b[i-pa+pb]){  
                printf("<\n");  
                return 0;  
            }  
        }  
        printf("=\n");  
    }  
    return 0;  
}

 

你可能感兴趣的:(Educational Codeforces Round 5 A)