Database, UVa 1592
来源:互联网 发布:数据恢复大师注册机 编辑:程序博客网 时间:2024/05/20 04:46
Database, UVa 1592
题目
题意
检查数据库中是否有不同的两行两列,他们相同列不同行的值相同。
分析
将两列不同行的值组成二元组,将二元组映射到int形成map,每次检查map中是否有相同的值。
代码实现
#include<iostream>#include<cstdio>#include<vector>#include<string>#include<map>#include<sstream>using namespace std;typedef pair<int,int> PII;const int maxr = 10000 + 5;const int maxc = 10 + 5;int m, n, db[maxr][maxc], cnt;map<string, int> id;int ID(const string& s) { if(!id.count(s)) { id[s] = ++cnt; } return id[s];}void find() { for(int c1 = 0; c1 < m; c1++) for(int c2 = c1+1; c2 < m; c2++) { map<PII, int> d; for(int i = 0; i < n; i++) { PII p = make_pair(db[i][c1], db[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.clear(); for(int i = 0; i < n; i++) { getline(cin, s); int lastpos = -1; for(int j = 0; j < m; j++) { int p = s.find(',', lastpos+1); if(p == string::npos) p = s.length(); db[i][j] = ID(s.substr(lastpos+1, p - lastpos - 1)); lastpos = p; } } find(); } return 0;}
遇到的问题
本题照抄书上刘汝佳老师代码,在处理带“,”的字符串读入时存在问题。
阅读全文
0 0
- UVA - 1592 Database
- UVa 1592 - Database
- UVa 1592 Database
- UVA 1592(p128)----Database
- UVA 1592 Database
- UVa 1592 Database
- Database UVA 1592数据库
- Uva 1592 Database
- uva 1592Database
- Database, UVa 1592
- UVA 1592 Database(map)
- UVa 1592 Database
- uva-1592Database[STL应用]
- UVA - 1592 Database map+pair
- Database UVA
- UVa 1592 - Database(pair+预处理)
- Problem 036——UVa 1592 - Database
- UVa #1592 Database (例题5-9)
- 3维可视化卷积神经网络
- POJ 1664 放苹果(m个苹果放入n个盘子
- callback回调函数 python
- C#代码规范
- 在switch case里使用continue
- Database, UVa 1592
- 简单的页面模板引擎(一)
- 外联结的ON条件与WHERE条件的区别
- 通过反射修改 被 private final static修饰的成员
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree dfs+set
- Oracle优化——外联结的执行计划
- spring_JUnit4测试_通过注解加载xml配置_@RunWith_@ContextConfiguration
- derby数据库源码分析(二)--页面分析
- 善良比聪明重要