UVA-1592-数据库

#include <bits/stdc++.h>
using namespace std;

#define MST(a,b) memset(a,b,sizeof(a));
#define CLR(a) MST(a,0);
#define _for(i,a,b) for(int i = (a); i < (b); ++i)

const int maxrow = 10000 + 10;
const int maxcol = 10 + 5;
int r = 0,c = 0, t = 1;
int arr[maxrow][maxcol];
map<string,int> mp;
map<pair<int,int>, int> mp2;

int main(int argc, char const *argv[])
{
    string temp;
    string x;
    while(cin >> r >> c ){
        int col = 0; t = 1; CLR(arr); mp.clear(); x.clear(); mp2.clear();
        getchar();
        _for(i,0,r){
            col = 0;
            getline(cin,temp);     
            int len = temp.length();
            _for(j,0,len){
                if(temp[j] != ',') x += temp[j];            
                if(temp[j] == ',' || j == len-1){
                    if(mp.count(x) == 0)  mp[x] = t++;
                    arr[i][col] = mp[x];
                    col++;
                    x.clear();
                }
                temp.clear();
            }
        }
       _for(i,0,c-1){
            for(int j = i+1; j < c; j++){
                _for(k,0,r){
                    int x1 = arr[k][i], x2 = arr[k][j];
                    if(mp2.count(make_pair(x1,x2))){
                        //第二次匹配,存在输出
                        cout << "NO" << endl;
                        cout << mp2[make_pair(x1,x2)] << " " << k+1 << endl;
                        cout << i+1 << " " << j+1 << endl;
                        goto kcl;
                   }else{
                       mp2[make_pair(x1,x2)] = k + 1;
                    }
                }
                mp2.clear();
            }
        }
        cout << "YES" << endl;
        kcl:{}
    }

    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.




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值