//1:getline的用法
//2:map的巧妙运用
//3:只枚举c1 c2,然后从上到下扫描各行,将c1 c2作为二元组,碰到新的行r就把其作为内容存放到map中,如果map中已经
//存在,即可求出所要的答案
//4:二元组有关
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#include <sstream>
#include <vector>
using namespace std;
#define max_r 10010
#define max_c 15
map<string, int> id_cache;
int id[max_r][max_c], n, m, cnt ;
int setID(const string & str) {
if(!id_cache.count(str)) {
id_cache[str] = ++cnt;
}
return id_cache[str];
}
void command() {
for(int c1 = 0; c1 < m; c1++)
for(int c2 = c1 + 1; c2 < m; c2++) {
map<pair<int, int>, int> d;
for(int i = 0; i < n; i++) {
pair<int, int> p = make_pair(id[i][c1], id[i][c2]);
if(d.count(p)) {
printf("NO\n");
printf("%d %d\n", d[p]+1, i+1);
printf("%d %d\n", c1+1, c2+1);
return;
}
d[p] = i;
}
}
printf("YES\n");
}
int main()
{
string s;
while(getline(cin, s)) {
stringstream ss(s);
if(!(ss >> n >> m)) break;
cnt = 0;
id_cache.clear();
for(int i = 0; i <n; i++) {
getline(cin, s);
int late_pos = -1;
for(int j = 0; j < m; j++) {
int pos = s.find(",", late_pos + 1); //返回“,”出现的位置
if(pos == string::npos) pos = s.length(); //若找不到,则返回最后一位的后一位
id[i][j] = setID(s.substr(late_pos +1, pos - late_pos - 1));
late_pos = pos;
}
}
command();
}
return 0;
}
Database uva1592
最新推荐文章于 2021-04-10 14:52:18 发布