Hduoj2054【水题】

/*A == B ?
Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 64017    Accepted Submission(s): 10012


Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
 

Input
each test case contains two numbers A and B.

 

Output
for each case, if A is equal to B, you should print "YES", or print "NO".
 

Sample Input
1 2
2 2
3 3
4 3
 

Sample Output
NO
YES
YES
NO
 

Author
8600 && xhd
 

Source
校庆杯Warm Up 
*/ 
#include<stdio.h>
#include<string.h>
char a[10000000], b[10000000];
int find(char * s)
{
	int i = strlen(s);
	while(s[i] != '.' && i)
	i--;
	if(i==0)
	return strlen(s);
	else return i; 
}
int main()
{
	while(scanf("%s%s", a, b) != EOF)
	{
		int m , n, i, j, k, l1,l2, p1, p2;
		m = strlen(a);
		n = strlen(b);
		p1 = find(a);
		for(i = 0; i < p1; i++)
		if(a[i] != '0')
		{
			l1 = i;
			break;
		}
		if(i == p1)// 数点前全部为0 或者 字符串全部为0 
		l1 = p1-1; //从 前一位开始比较 
		p2 = find(b);
		for(j = 0; j < p2; j++)
		if(b[j] != '0')
		{
			l2 = j;
			break;
		}
		if(j == p2)
		l2 = p2-1; 
		for(i = m-1; i >= p1; i --)//去尾0 
		if(a[i] =='0' || a[i] == '.')
		a[i] = '\0';
		else 
		break;
		for( j = n-1; j >= p2; j --)
		if(b[j] == '0' || b[j] == '.')
		b[j] = '\0';
		else
		break;
		if(strcmp(a+l1, b+l2) == 0)
		printf("YES\n");
		else
		printf("NO\n"); 
	}
	return 0;
} 

你可能感兴趣的:(c)