[恢]hdu 2054

2011-12-17 01:37:11

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2054

题意:输入2个数字,问你是否相等(大数)。

mark:RE1次,数组要开到10w。。。蛋疼。

这题其实简单,依次做三件事:加小数点(若无小数点),去末尾0,去前导0。

没有负数的情况。

代码:

# include <stdio.h>
# include <string.h>


char s1[100010], s2[100010] ;


void AddDecimal (char *s)
{
int i ;
for (i = 0 ; s[i] ; i++)
if (s[i] == '.') return ;
s[i] = '.', s[i+1] = '\0' ;
}


void DelZeroEnd (char *s)
{
int len = strlen(s) -1 ;
while (s[len] == '0') s[len--] = '\0' ;
}

char *DelZeroStart (char *s)
{
while (*s)
{
if (*s != '0') return s ;
s++ ;
}
}

char *format(char *s)
{
AddDecimal (s) ;
DelZeroEnd(s) ;
s = DelZeroStart(s) ;
return s ;
}


int main ()
{
while (~scanf ("%s %s", s1, s2))
puts (strcmp (format(s1), format(s2)) == 0 ?
"YES" : "NO") ;
return 0 ;
}



posted @ 2012-01-06 18:43  Seraph2012  阅读(219)  评论(0编辑  收藏  举报