您的位置:首页 > 其它

HDU 2054 A == B ?

2014-01-25 01:13 309 查看
题目:

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

收获很大的一道题,一开始看到这道题笑了,做到最后差点哭了,还好有度娘。

题解:

要考虑到这种数据,00123.123000 123.123  是相等的。

所以只要对输入的数据简化即可。

用到strchr函数:

原型:extern char *strchr(char *s,char c);

用法:#include <string.h>

功能:查找字符串s中首次出现字符c的位置

说明:返回首次出现c的位置的指针,如果s中不存在c则返回NULL。


代码:

#include<stdio.h>
#include<string.h>
char a[20000],b[20000];
void simplify(char*p)
{
while(*p=='0') p++;
if(strchr(p,'.'))
{
int len=strlen(p);
char *s=p+len-1;
while(*s=='0') *(s--)='\0';
if(*s=='.') *s='\0';
}
}
int main()
{
while(~scanf("%s%s",a,b))
{
simplify(a);
simplify(b);
if(strcmp(a,b)==0)
printf("YES\n");
else printf("NO\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: