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。本题中用来判断是否为小数。很方便.。