您的位置:首页 > 其它

Database uva1592

2016-03-29 09:09 495 查看






//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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: