hdu 2054 判断A==B?

Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
 

 

Input
each test case contains two numbers A and B.
 

 

Output
for each case, if A is equal to B, you should print "YES", or print "NO".
Sample Input
1 2
2 2
3 3
4 3
 

Sample Output
NO
YES
YES
NO
代码:
#include<stdio.h>
#include<string.h>
void fun(char *p)
{ int len=strlen(p);
   char *t=p+len-1;
   if(strchr(p,'.'))
     while(*t=='0') *t--=0;
   if(*t=='.') *t=0;
}
main()
{
  char a[100024],b[100024];
  char *p_a,*p_b;
 while (scanf("%s%s", &a, &b) != -1) 
   {
     p_a=a;p_b=b;
     while(*p_a=='0') p_a++;
     while(*p_b=='0') p_b++;
     fun(p_a);fun(p_b); 
     puts(strcmp(p_a, p_b) ? "NO" : "YES");
   }      
}
这题主要是判断001.00=1。首先去掉没用的0,然后再判断。
这题也引用了#include<string.h>里面的strchr函数。
strchr(char *p,char ch)用来找第一次出现ch的位置
刚发现,这题有个BUG,就是 -01.00 -1时,结果竟然是NO,可是这代码AC了,郁闷呀
所以,还得改一下
#include<stdio.h>
#include<string.h>
void fun(char *p)
{ int len=strlen(p);
   char *t=p+len-1;
   if(strchr(p,'.'))
     while(*t=='0') *t--=0;
   if(*t=='.') *t=0;
}
main()
{
  char a[100024],b[100024];
  char *p_a,*p_b;
 while (scanf("%s%s", &a, &b) != -1) 
   { int j_a=0,j_b=0;
     p_a=a;p_b=b;
     if(*p_a=='-') {p_a++;j_a++;}
     if(*p_b=='-') {p_b++;j_b++;}
     if(j_a==j_b)
     {
     while(*p_a=='0') p_a++;
     while(*p_b=='0') p_b++;
     fun(p_a);fun(p_b); 
     puts(strcmp(p_a, p_b) ? "NO" : "YES");
     }
     else 
     printf("NO/n");
   }      
}
哈,这样就没问题了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值