HDU 2054 A == B ?

题目:

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值