UVA 1592

#include<iostream>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
typedef pair<int,int> Elem;
int num;//编号
map<string,int > ID ;//字符串映射到ID
int a[10005][15]; //存编号
int getID(const string &s)
{
  if(ID.count(s)!=0) //已分配
    return ID[s] ;
  else
    return ID[s]=num++; //分配新ID

}
void find(int n,int m)
{
  for(int c1=0;c1<m;c1++)
  {
    for(int c2=c1+1;c2<m;c2++)
    {
      map<Elem,int> mp;
      for(int r=0;r<n;r++)
      {
        Elem p=make_pair(a[r][c1],a[r][c2]);
        if(mp.count(p))
        {
         printf("NO\n");
         printf("%d %d\n%d %d\n",mp[p]+1,r+1,c1+1,c2+1);
         return ;
        }
        else
        mp[p]=r;
      }
    }
  }
printf("YES\n");
}
void read(int n,int m)
{
  ID.clear();
  num=1;
  string cmp;
  for(int i=0;i<n;i++)
  {
    getline(cin,cmp);
    int pos=-1; //指向每次停下来的位置
    for(int j=0;j<m;j++)
    {
      int p=cmp.find(',',pos+1); //从新位置找到逗号,因为逗号分隔开来
      if(p==string::npos)
      p=cmp.length() ;//找到末尾了
      a[i][j]=getID(cmp.substr(pos+1,p-1-pos));
      pos=p;
    }
  }
}
int main()
{
  int n,m;
  while(cin>>n>>m)
  {
    getchar();//可以吞掉回车
    read(n,m);
    find(n,m);
  }
}

posted @ 2019-05-28 22:22  ACM-Lxw  阅读(74)  评论(0编辑  收藏  举报