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; }
相关文章推荐
- 客户端GUI测试技术和自动化测试架构设计简谈
- python None与Null
- 计算广告与机器学习-技术共享平台
- lightoj 1068 - Investigation 数位DP
- p(343)通用汇点
- 高层论坛︱王家耀院士:“互联网+”时空大数据与智慧城市(3)
- 我的半年的大学生活
- java自定义filter
- 互联网+ 从IT到DT(读书笔记)
- Smobiler基于.NET框架开发移动应用内部系统—工作单功能(开发日志七)
- 360笔试--字符置换
- Android使用SharedPreferences保存对象
- Asp.Net Web API 2第九课——自承载Web API
- BZOJ 2461: [BeiJing2011]符环
- React下载网址
- ORACLE日期时间函数大全
- Eclipse Maven插件clean 异常
- localStorage 和 sessionStorage 的用法
- Asp.Net Web API 2第八课——Web API 2中的属性路由
- 互联网+时代创业黄金指南(读书笔记)