杭电ACM 第2094题

#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
void main(){
    int n;
    while(cin>>n&&n){
        
        

        string str1[1000],str2[1000];
        int k=n;
        string str11,str22;

        if(n==1)
        {
            cin>>str11>>str22;
            cout<<"Yes"<<endl;

            continue;
        }

        int z1=1;
        int z2=1;
        for(int i=0;i<n;++i){
            if(i==0)
            {
                cin>>str1[0]>>str2[0];
            }
            else{
                cin>>str11;
                cin>>str22;
                bool t1=true;
                bool t2=true;
                bool t3=false;
                bool t4=false;
                for(int j=0;j<i;++j){
                    if(!t3&&str11==str1[j])
                    {
                        t1=false;
                        t3=true;
                    }
                    if(!t4&&str22==str2[j])
                    {
                        t2=false;
                        t4=true;
                    }
                    if(t4&&t3)
                        break;
                    
                    
                }
                if(t1)
                    str1[z1++]=str11;
                
                if(t2)
                    str2[z2++]=str22;

                
            }
        }

        

        bool tt[1000];
        memset(tt,true,sizeof(tt));
        for(int a=0;a<z1;++a){
            for(int b=0;b<z2;++b){
                if(str1[a]==str2[b])
                {
                    tt[a]=false;
                    break;
                }
            }
        }
        int count=0;
        for(int fff=0;fff<z1;++fff){
            if(tt[fff])
                ++count;

        }
        if(count==1)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

        
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值