昨晚写的,学习了用map映射自定义类型,还有operator。
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#define MAXN_N_LEN 10010
#define MAXN_M_LEN 11
#define MAXN_STR_LEN 90
using namespace std;
struct Point{
int n1, n2;
};
struct cmp_Point {
bool operator () (const Point &k1, const Point &k2) const {
if(k1.n1 != k2.n1)
return k1.n1 < k2.n1;
if(k1.n2 != k2.n2)
return k1.n2 < k2.n2;
return false;
}
};
int table[MAXN_N_LEN][MAXN_M_LEN];
char temp[MAXN_N_LEN][MAXN_STR_LEN];
string temp_str;
map<string, int> IDcache;
vector<string> ID_card;
int ID_num(string s) {
if(IDcache.count(s)) return IDcache[s];
ID_card.push_back(s);
return IDcache[s] = ID_card.size() - 1;
}
int main() {
int r, c;
while(cin >> r >> c) {
int sign = 0;
getchar();
for(int i = 0; i < r; i++)
gets(temp[i]);
for(int i = 0; i < r; i++) {
int k = 0, q = 0;
for(int j = 0; j <= strlen(temp[i]); j++)
if(temp[i][j] == ','|| j == strlen(temp[i])) {
table[i][q++] = ID_num(temp_str);
temp_str.clear();
}
else
temp_str += temp[i][j];
}
for(int i = 0; i < c - 1; i++) {
for(int j = i + 1; j < c; j++) {
map<Point, int, cmp_Point> table_num;
for(int k = 0; k < r; k++) {
Point p;
p.n1 = table[k][i];
p.n2 = table[k][j];
if(!table_num.count(p))
table_num.insert(pair<Point, int> (p, k));
else {
cout << "NO" << endl;
cout << table_num[p] + 1 << " " << k + 1 << endl;
cout << i + 1 << " " << j + 1 << endl;
sign = 1;
break;
}
}
if(sign) break;
}
if(sign) break;
}
if(!sign)
cout << "YES" << endl;
memset(table, 0, sizeof(table));
memset(temp, 0, sizeof(temp));
temp_str.clear();
IDcache.clear();
ID_card.clear();
}
return 0;
}