A == B?

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;
}

原题链接 http://acm.hdu.edu.cn/showproblem.php?pid=2054

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值