HDU-2054 A==B?

#include<stdio.h>
#include<string.h>
char n[100000], m[100000];
int main()
{
int i, j, len_n, len_m, flag, len_last, len_late,doc, q, p, count, start;
char ch;
while(1)
{
memset(n, 0, sizeof(n));
memset(m, 0, sizeof(m));
flag = i = j = doc = count = start = 0;
while(1)
{
if(scanf("%c", &ch) == EOF) return 0;
if(ch == '\n' && start == 1) break;
else if(ch != ' ' && ch != '\n' && flag == 0)
{
n[i++] = ch;
}
else if(ch == ' ' || ch == '\n')
{
flag = 1;
start = 1;
}
else m[j++] = ch;

}
len_n = strlen(n);
len_m = strlen(m);
if((n[0] == '-' && m[0] != '-') || (n[0] != '-' && m[0] == '-'))
{
printf("NO\n");
continue;
}
for(i = n[0] != '-'? 0:1; i<len_n && n[i] - '0'== 0; i++);
for(j = m[0] != '-'? 0:1; j<len_m && m[j] - '0'== 0; j++);
len_n -= i;
len_m -= j;
len_last = len_n < len_m? len_n:len_m;
len_late = len_n + len_m - len_last;
{
for(; count < len_last; i++, j++, count++)
if(n[i] - '0' != m[j] - '0') break;
else if(n[i] == '.') doc = 1;
if(count >= len_late)
{
printf("YES\n");
}
else
{
if(len_n > len_m)
{
if(doc != 1 && n[i] != '.') printf("NO\n");
else
{
for(i = n[i] == '.'? i+1: i; i<strlen(n); i++)
if(n[i] - '0' != 0 ) break;
if(i>=len_n) printf("YES\n");
else printf("NO\n");
}

}
else if(len_n < len_m)
{
if(doc != 1 && m[j] != '.') printf("NO\n");
else
{
for(j = m[j] == '.'? j+1: j; j<strlen(m); j++)
if(m[j] - '0' != 0 ) break;
if(j>=len_m) printf("YES\n");
else printf("NO\n");
}
}
else if(len_n == len_m) printf("NO\n");
}
}

}
return 0;
}

1.考虑数字前面的0

2.考虑小数点后的0

3.考虑大数字

上一篇:LeetCode Remove Linked List Elements 删除链表元素


下一篇:SQL Server 存储过程(转)