HDU-2054

HDU-2054

A - 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
NO
YES
YES
NO

解题心得:
一道大数题,但并没有涉及大数的运算。所以这道题也较为简单,需要注意的两点:
区分1.0和1的情况,去掉0和".";
区分1.01和1.010的情况,去掉0;

伪代码:

#include <iostream>
#include <string.h>
#include <string>
#include <stdlib.h>

using namespace std;


//判断是否为小数
int Choose(char list[] , int l) {
	for (int i = 0; i < l;i++) {
		if (list[i] == '.') {
			return 1;
		}
	}
	return 0;
}

void Delete(char list[], int l) {
	if (Choose(list, l)) {//可以用函数strstr(a,".")
		int x = l - 1;
		//如若出现1.100或者1.1情况
		while (list[x] == '0') {
			list[x] = 0;
			x--;
		}
		for (int i = 0; i < x;i++)
		{
			cout << list[i];
		}
		cout << endl;
		//如果出现1.0 或者1情况,注意
		if (list[x] == '.') {
			list[x] = 0;
			x--;
		}
		l = 1;
	}
}

int main() {
	char a[10000], b[10000];
	while (cin >> a >> b) {
		int l1 = strlen(a), l2 = strlen(b);
		Delete(a, l1);
		Delete(b, l2);
		if (strcmp(a, b) == 0) {
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	system("pause");
	return 0;
}

strstr(“处理字符串”,”搜索字符串(字符)”),功能是在处理字符串中寻找搜索字符串,并返回搜索字符串,否则返回null。本题中用来判断是否为小数。很方便.。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值