1060. Are They Equal (25)

#include <iostream>
#include <string.h>

using namespace std;

struct node
{
	int d;
	char s[110];
};

int n;

node getnode(char s[])
{
	int firstpos = -1, pointpos = -1, count = 0, i, len = strlen(s);
	char ch;
	node nod;

	for(i = 0; i < len; i++)
	{
		ch = s[i];
		if(ch == '.')
		{
			pointpos = i;
		}
		else if((ch == '0' && firstpos >= 0) || (ch > '0'))
		{
			if(firstpos == -1)
			{
				firstpos = i;
			}

			if(count < n)
			{
				nod.s[count++] = ch;
			}
		}
	}

	for(i = count; i < n; i++)
	{
		nod.s[count++] = '0';
	}
	nod.s[n] = '\0';

	int d = 0;
	if(firstpos >= 0)
	{
		if(pointpos == -1)
		{
			pointpos = len;
		}

		d = pointpos - firstpos;
		if(d < 0)
		{
			d += 1;
		}
	}
	nod.d = d;

	return nod;
}

int main()
{
	char a[110], b[110];
	scanf("%d%s%s", &n, a, b);

	node n1 = getnode(a);
	node n2 = getnode(b);

	if(strcmp(n1.s, n2.s) == 0 && n1.d == n2.d)
	{
		printf("YES 0.%s*10^%d\n", n1.s, n1.d);
	}
	else
	{
		printf("NO 0.%s*10^%d 0.%s*10^%d\n", n1.s, n1.d, n2.s, n2.d);
	}
	
	system("pause");
	return 0;
}

 

posted on 2025-11-23 17:11  王景迁  阅读(2)  评论(0)    收藏  举报

导航