// http://acm.hdu.edu.cn/showproblem.php?pid=2054 A==B?
#include
#include<
string.h>
#include
const
long maxn = 100024;
/*
要考虑的情况 1,10)、(100,100.00)、(0001, 01.0)、(01.1001 , 1.101)、(1.0100,1.01)
*/
void partition_string(
char _a[],
char _a1[],
char _a2[])
{
char *str;
int i,j,len;
str = strchr(_a,
'.');
//
if(str!=NULL)
{
len = strlen(_a);
strncpy(_a1,_a,(str-_a)/
sizeof(
char));
_a1[(str-_a)/
sizeof(
char)] =
'/0';
for(j = 0, i = (str-_a)/
sizeof(
char) + 1;i< len;i++,j++)
_a2[j] = _a[i];
_a2[j] =
'/0';
}
else
{
strcpy(_a1,_a);
strcpy(_a2,
"0");
}
}
int check(
char _str[])
// 用于去掉 小数区的0
{
int i,len = strlen(_str);
for(i = len-1;i>=0;i--)
{
if(_str[i] ==
'0') _str[i] =
'/0';
else
return i;
//if(_str[i] != '0' ) break;
}
return -1;
}
int del(
char _str[])
// 用于去掉 整数区的0
{
int i,len = strlen(_str);
for(i= 0;i < len && _str[i]==
'0';i++)
;
return i;
//返回 第一个不等于0的下标
}
int main()
{
//freopen("in.txt","r",stdin);
char a[maxn],b[maxn],temp[10];
char a1[maxn],a2[maxn],b1[maxn],b2[maxn];
while(scanf(
"%s%s",a,b)!=EOF)
{
//memset(a1,NULL,500);memset(a2,NULL,500);
//memset(b1,NULL,500);memset(b2,NULL,500);
partition_string(a,a1,a2);partition_string(b,b1,b2);
check(a2),check(b2);
//a1=,b1=;
if(strcmp(a1+del(a1),b1+del(b1)) ==0 && strcmp(b2,a2)==0)
// strcmp(a1+del(a1),b1+del(b1))就可以很好的比较
printf(
"YES/n");
else printf(
"NO/n");
//memset(a,NULL,500);memset(b,NULL,500);
}
return 0;
}
测试发布 代码
最新推荐文章于 2023-06-29 15:32:14 发布