Y - A == B ?

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

NOYESYESNO

题意:比较a,b,相等输出YES 否则输出NO ,一开始以为是水题结果定义了longlong 都wa,显然是超大数比较,只能用字符串数组,不像大数n次方,只需要把无意义0清除,小数点也可以清除的话也除去,不过要注意一点-0=0;把0清除后,只要有一个数组“-”,一个数组“\0”就是-0=0,了

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char a[100000];
char b[100000];//定义超大数组
void judge(char str[]);
int main()
{
 int i,j,flag1=-1,flag2=-1;
 while(cin>>a>>b)
 {
  judge(a);//处理数组a,b
  judge(b);
  if(a[0]=='-'&&a[1]=='\0'&&b[0]=='\0')//判断是否为-0,和0
  {
   cout<<"YES"<<endl;
  }
  else if(strcmp(a,b))
  {
   cout<<"NO"<<endl;
  }
  else
  {
   cout<<"YES"<<endl;
  }
 }
}
void judge(char str[])
{
 int len,i;
 len=strlen(str);
 if(strstr(str,"."))//strstr数找字符串的子数列是否有"."
 {
  for(i=len-1;str[i]=='0';i--)
  {
   str[i]='\0';//清除0
  }
  if(str[i]=='.')//"."也能去的话也去掉
  {
   str[i]='\0';
  }
 }
 if(str[0]=='0')//清除前导0
 {
  while(str[0]=='0')
  {
   for(i=0;i<len-1;i++)
   {
    str[i]=str[i+1];
   }
   str[len-1]='\0';
   len--;
  }
  
 }
 if(str[0]=='-')//负数时,也清除前导0
 {
  while(str[1]=='0')
  {
   for(i=1;i<=len-1;i++)
   {
    str[i]=str[i+1];
   }
  }
  a[len-1]='\0';
  len--;
 }
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值