A == B ?
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
代码如下
#include<iostream>
#include<string>
using namespace std;
int main(){
string str1,str2;
while(cin>>str1>>str2){
int l1=str1.length();
int l2=str2.length();
int f1=0;
int f2=0;
for(int i=0;i<l1;i++){
if(str1[i]=='.') {
f1=1;
break;
}
}
for(int i=0;i<l2;i++){
if(str2[i]=='.') {
f2=1;
break;
}
}
if(l1==l2){
if(str1==str2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else if(l1<l2){
if(f1==0&&f2==0){
if(str1==str2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
if(f1==1&&f2==0){
cout<<"NO"<<endl;
}
if(f1==1&&f2==1){
for(int i=0;i<l2-l1;i++){
str1=str1+"0";
}
if(str1==str2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
if(f1==0&&f2==1){
str1=str1+".";
for(int i=1;i<l2-l1;i++){
str1=str1+"0";
}
if(str1==str2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
else{//l1>l2
if(f1==0&&f2==0){
if(str1==str2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
if(f1==0&&f2==1){
cout<<"NO"<<endl;
}
if(f1==1&&f2==1){
for(int i=0;i<l1-l2;i++){
str2=str2+"0";
}
if(str1==str2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
if(f1==1&&f2==0){
str2=str2+".";
for(int i=1;i<l1-l2;i++){
str2=str2+"0";
}
if(str1==str2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
}
return 0;
}