大整数比较大小
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=73
#include <stdio.h> #include <string.h> #define MAXN 1005 char a[MAXN],b[MAXN]; int len1,len2; int main() { while(scanf("%s%s",a,b)) { if(a[0]=='0'&&b[0]=='0') break; int i; len1=strlen(a); len2=strlen(b); if(a[0]!='-'&&b[0]=='-') printf("a>b\n"); if(a[0]=='-'&&b[0]!='-') printf("a<b\n"); if(a[0]=='-'&&b[0]=='-')///同为负数 { if(len1>len2) printf("a<b\n"); if(len1<len2) printf("a>b\n"); if(len1==len2) { for(i=0; i<len1; i++) { if(a[i]>b[i]) { printf("a<b\n"); break; } if(a[i]<b[i]) { printf("a>b\n"); break; } } } if(i==len1) printf("a==b\n"); } if(a[0]!='-'&&b[0]!='-')///同为正数 { if(len1>len2) printf("a>b\n"); if(len1<len2) printf("a<b\n"); if(len1==len2) { for(i=0; i<len1; i++) { if(a[i]>b[i]) { printf("a>b\n"); break; } if(a[i]<b[i]) { printf("a<b\n"); break; } } } if(i==len1) printf("a==b\n"); } } return 0; }