A-B Problem
来源:互联网 发布:淘宝电子积木 编辑:程序博客网 时间:2024/05/24 02:20
描述
A+B问题早已经被大家所熟知了,是不是很无聊呢?现在大家来做一下A-B吧。
现在有两个实数A和B,聪明的你,能不能判断出A-B的值是否等于0呢?
输入
有多组测试数据。每组数据包括两行,分别代表A和B。
它们的位数小于100,且每个数字前中可能包含+,- 号。
每个数字前面和后面都可能有多余的0。
每组测试数据后有一空行。
输出
对于每组数据,输出一行。
如果A-B=0,输出YES,否则输出NO。
样例输入
1
1
1.0
2.0
样例输出
YES
NO
答案:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
const int M=100;
void back(char* c,int &l)
{
if(strchr(c,'.') == NULL)
return ;
for(int i=l-1;i>=1;i--)
{
if(c[i]!='0')
break;
l--;
}
if(c[l-1]=='.')
l--;
c[l]='\0';
//puts("after back->");
//puts(c);
}
void front(char* c,int &l,bool &f)
{
int cnt = isdigit(c[0]) ? 0 : 1;
if(c[0]=='-')
f = false;
for(int i=cnt;i<l-1;i++)
{
if(c[i+1]=='.' || c[i]!='0')
break;
cnt++;
}
if(cnt)
{
for(int i=0;i<l-cnt;i++)
c[i] = c[i+cnt];
c[l-cnt] = '\0';
}
//puts("after front->");
//printf(f?"+ ":"- ");
//puts(c);
}
void deal(char *c,bool &f)
{
int l = strlen(c);
f = true;
back(c,l);
front(c,l,f);
}
bool Cmp(char* A,char* B,bool a,bool b)
{
if(strcmp(A,B) == 0)
{
if(strcmp(A,"0") == 0 || a^b == 0)
return true;
}
return false;
}
int main()
{
char A[M],B[M];
bool a,b;
while(~scanf("%s%s",A,B))
{
deal(A,a);
deal(B,b);
puts(Cmp(A,B,a,b)?"YES":"NO");
}
return 0;
}
- problem 1000: A+B problem
- Problem 1000 A+B Problem
- Problem - 1000 A + B Problem
- A + B Problem
- A + B Problem
- 1000 A+B Problem
- 1001 A + B Problem
- A+B Problem
- 1000 A+B Problem
- A + B Problem
- A + B Problem
- 1000 A + B Problem
- 1000 A+B Problem
- A + B Problem
- A + B Problem II
- A + B Problem II
- POJ1001 -- A-B Problem
- A + B problem II
- Linux Crontab 定时任务 命令详解
- COM学习笔记(二)CoCreateInstance具体内部实现
- 注册表编程
- 【MyEclipse】MyEclipse查找功能巧用
- 二十三种设计模式(java版)之Adapter
- A-B Problem
- C#面向对象基础
- 小媛在努力
- 多边形编辑器(一)
- Git技巧
- satchmo汉化
- 统计难题
- QQ邮箱网盘:可直接调用微云和Dropbox
- MySQL数据库集群实现负载均衡的安装配置详解