A == B ?(思维)
A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 121015 Accepted Submission(s): 19354
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
Author
8600 && xhd
思路:把小数点后面的多余的零去掉,同时注意如果最后一位是小数点的话,也要去掉,(就在这里wa了好多次)
上代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e6+5;
char a[maxn],b[maxn];
int qSpot(char *c,int lenn){
int len = lenn,len1 = lenn;
for(int i = 0;i<len;i++){
if(c[i]=='.'){
len = i;
break;
}
}
int s = 0;
for(int i = len1-1;i>=len;i--){
if(c[i]=='0'){
s++;
}
else{
break;
}
}
if(c[len1-s-1] == '.') s++;
return len1 - s;
}
int main()
{
while(~scanf("%s %s",a,b)){
int len = strlen(a);
int len1 = strlen(b);
len = qSpot(a,len);
len1 = qSpot(b,len1);
//printf("%d %d\n",len,len1);
if(len != len1) printf("NO\n");
else{
bool falg = true;
for(int i = 0;i<len;i++){
if(a[i]!=b[i]){
falg = false;
}
if(falg == false) break;
}
if(falg) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}