A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 96648 Accepted Submission(s): 15372
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
做本题是要判断是否存在前导0存在以及小数点后是否最后几位是0;
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
char a[1000005],b[1000005];
int Judge(char *a, int &x){
int len = strlen(a),i = 0,flag = 0;
while(a[i + 1] != '.' && a[i] == '0' && i < len)
i ++;
x = i;
for(i = 0; i < len; i ++)
if(a[i] == '.')
flag = 1;
i = len - 1;
while(i >= 0 && a[i] == '0' && flag && a[i] != '.'){
a[i] = '\0';
i --;
}
if(a[i] == '.')
a[i] = '\0';
}
int main(){
while(cin >>a >>b){
int x,y,flag = 0;
Judge(a,x);
Judge(b,y);
if(strlen(a) - x != strlen(b) - y){
printf("NO\n");
continue;
}
else{
while(x < strlen(a)){
if(a[x] != b[y]){
flag = 1;
break;
}
x ++; y ++;
}
if(flag)
printf("NO\n");
else
printf("YES\n");
}
}
return 0;
}