Database(UVa 1592)

#include <iostream>
#include <bits/stdc++.h>
#define maxn 100001
using namespace std;
map<string,int>IDcache;
vector<string>data;
map<pair<int,int>,int>mp;
int a[maxn][15];


int main()
{
    int r,c;
    string s,s0;
    while(cin>>r>>c)
    {
        getchar();
        for(int i = 0;i<r;i++)
        {
            int xcol = 0;
            getline(cin,s);
            for(int j = 0;j<s.size();j++)
            {
                if(s[j]==','||j==s.size()-1)
                {
                    if(j==s.size()-1)
                            s0+=s[j];
                    if(!IDcache[s0])
                    {
                        data.push_back(s0);
                        IDcache[s0] = data.size()-1;
                    }
                    a[i][xcol++] = IDcache[s0];
                    s0 = "";
                }
                else
                    s0+=s[j];
            }
        }
//        for(int i = 0;i<r;i++)
//        {
//            for(int j = 0;j<c;j++)
//            {
//                cout<<a[i][j]<<" ";
//            }
//            cout<<endl;
//        }
        int flag = 1;
        for(int i = 0;i<c-1;i++)
        {
            if(!flag) break;
            for(int j = i+1;j<c;j++)
            {
                mp.clear();
                if(!flag) break;
                for(int k = 0;k<r;k++)
                {
                    int c1 = a[k][i];
                    int c2 = a[k][j];
                    if(!mp.count(make_pair(c1,c2)))
                    {
                        mp[make_pair(c1,c2)] = k;
                    }
                    else
                    {
                        cout<<"NO"<<endl;
                        cout<<mp[make_pair(c1,c2)]+1<<" "<<k+1<<endl;
                        cout<<i+1<<" "<<j+1<<endl;
                        flag = 0;
                        break;

                    }
                }
            }
        }
        if(flag) cout<<"YES"<<endl;
    }
    return 0;
}
/**
3 3
How to compete in ACM ICPC,Peter,peter@neerc.ifmo.ru
How to win ACM ICPC,Michael,michael@neerc.ifmo.ru
Notes from ACM ICPC champion,Michael,michael@neerc.ifmo.ru
2 3
1,Peter,peter@neerc.ifmo.ru
2,Michael,michael@neerc.ifmo.ru
**/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值