Input

Input contains several datasets. The first line of each dataset contains two integer numbersn and m (1n10000, 1m10), the number of rows and columns in the table. The following n lines contain table rows. Each row hasm column values separated by commas. Column values consist of ASCII characters from space (ASCII code 32) to tilde (ASCII code 126) with the exception of comma (ASCII code 44). Values are not empty and have no leading and trailing spaces. Each row has at most 80 characters (including separating commas).

Output

For each dataset, if the table is in PNF write to the output file a single word ``YES" (without quotes). If the table is not in PNF, then write three lines. On the first line write a single word ``NO" (without quotes). On the second line write two integer row numbers r1 andr2 (1r1,r2n,r1r2), on the third line write two integer column numbers c1 andc2 (1c1,c2m,c1c2), so that values in columnsc1 andc2 are the same in rowsr1 andr2.

Sample Input

3 3
How to compete in ACM ICPC,Peter,peter@neerc.ifmo.ru
How to win ACM ICPC,Michael,michael@neerc.ifmo.ru
Notes from ACM ICPC champion,Michael,michael@neerc.ifmo.ru
2 3
1,Peter,peter@neerc.ifmo.ru
2,Michael,michael@neerc.ifmo.ru

Sample Output

NO
2 3
2 3
YES
这道题应该使用map来对数据做个一一映射,先将输入的字符串通过map映射成数字,再输入到一个数组里。
之后把c1,c2两列的内容作为一个二元组存到一个map中,由于需要存入两个数据,在这里可以使用pair,在map中就是map<pair<int,int>,int>。
这儿写一下pair的用法:

makr_pair:

pair<int ,int >p (5,6);

pair<int ,int > p1= make_pair(5,6);

pair<string,double> p2 ("aa",5.0);

pair <string ,double> p3 = make_pair("aa",5.0);

有这两种写法来生成一个pair。

如何取得pair的值呢。。

每个pair 都有两个属性值  first  和second

cout<<p1.first<<p1.second;

注意是属性值而不是方法。


 #include<iostream>
#include<map>
#include<string> using namespace std; map<string, int> IDcache;
map<pair<int, int>, int> NewIDcache;
int a[][];
int n, m; void match()
{
int x, y;
for (int c1 = ; c1 < m-; c1++)
{
for (int c2 = c1 + ; c2 < m; c2++)
{
for (int r = ; r < n; r++)
{
x = a[r][c1];
y = a[r][c2];
if (!NewIDcache.count(make_pair(x, y))) NewIDcache[make_pair(x, y)] = r;
else
{
cout << "NO" << endl;
cout << NewIDcache[make_pair(x, y)] + << " " << r + << endl;
cout << c1 + << " " << c2 + << endl;
return;
}
}
NewIDcache.clear();
}
}
cout << "YES" << endl;
} int main()
{
while (cin >> n >> m)
{
int t = ;
getchar();
string str;
IDcache.clear();
NewIDcache.clear();
for (int i = ; i < n; i++)
{
int count = ;
str.clear();
getline(cin, str);
int l = str.length();
string s;
for (int j = ; j < l; j++)
{
if (str[j] != ',') s = s + str[j];
if (str[j] == ',' || j == l-)
{
if (!IDcache.count(s)) IDcache[s] = t++;
a[i][count++] = IDcache[s];
s.clear();
}
}
}
match();
}
}

 

UVa 1592 数据库(c++pair)的更多相关文章

  1. UVA 10245 The Closest Pair Problem 最近点问题 分治算法

    题意,给出n个点的坐标,找出两点间最近的距离,如果小于10000就输出INFINITY. 纯暴力是会超时的,所以得另辟蹊径,用分治算法. 递归思路将点按坐标排序后,分成两块处理,最近的距离不是在两块中 ...

  2. UVa 1592 Database(巧用map)

    Peter studies the theory of relational databases. Table in the relational database consists of value ...

  3. UVa - 1592 Database(STL,优化)

    给一个n行m列的数据库表格,问有没有两个行 r1,r2 和 c1,c2,满足(r1,r2)的元素=(c1,c2)的元素. n≤10000,m≤10. 直接枚举4个肯定会T的.可以只枚举c1 c2,然后 ...

  4. UVa 1592 Database (map)

    题意:给出n行m列的数据库(数据范围: n 1~10000, m 1~10), 问你能不能找出两行r1, r2,使得这两行中的c1, c2列是一样的, 即(r1,c1)==(r2,c1) && ...

  5. UVA 10245 - The Closest Pair Problem

    Problem JThe Closest Pair ProblemInput: standard inputOutput: standard outputTime Limit: 8 secondsMe ...

  6. UVA - 1592 Database 枚举+map

    思路 直接枚举两列,然后枚举每一行用map依次记录每对字符串出现的是否出现过(字符串最好先处理成数字,这样会更快),如果出现就是"NO",否则就是"YES". ...

  7. UVA 1592 DataBase

    思路: 知识补充: ①make_pair和pair: /*pair是将2个数据组合成一个数据,当需要这样的需求时就可以使用pair,如stl中的map就是将key和value放在一起来保存.另一个应用 ...

  8. UVa 10245 The Closest Pair Problem (分治)

    题意:给定 n 个点,求最近两个点的距离. 析:直接求肯定要超时的,利用分治法,先把点分成两大类,答案要么在左边,要么在右边,要么一个点在左边一个点在右边,然后在左边或右边的好求,那么对于一个在左边一 ...

  9. Database UVA - 1592

    对于每组数据,首先通过一个map将每个字符串由一个数字代替,相同的字符串由相同数字代替,不同的字符串由不同数字代替.那么题目就变为了询问是否存在行r1,r2以及列c1,c2使得str[r1][c1]= ...

随机推荐

  1. ubuntu 12.04安装TP-LINK TL-WN725N v2

    用了一个上午,折腾完毕,分享如下. 1.先试了ndiswrapper和compat-wireless,各种不给力.后来看这篇博文<Ubuntu12.04下安装TL-WN322G+无线网卡驱动(R ...

  2. C++-理解构造函数、析构函数执行顺序

    先初始化序列中的函数调用,如果基类构造函数为非引用传递,则引起参数的拷贝构造 再: 先类内的成员构造函数(拷贝/默认),再类的构造函数:先基类,再派生类: 本文主要说明对象创建时构造函数的执行顺序,对 ...

  3. 基于K2的集成供应链流程解决方案

    基于K2的集成供应链流程解决方案http://www.k2software.cn/zh-hans/scm-solution 一.详细功能模块 需求管理模块多渠道管理.需求计划.需求感知与传递市场营销及 ...

  4. GPT分区基础知识及如何在GPT分区上安装WIN7

    大硬盘和WIN8系统,让我们从传统的BIOS+MBR模式升级到UEFI+GPT模式,现在购买的主流电脑,都是预装WIN8系统,为了更好的支持2TB硬盘,更快速的启动win8,预装系统都采取了GPT分区 ...

  5. AndroidStudio导入第三方开源库 --文件夹源码

    1 在已打开的项目中  File-New-ImportModule 选择开源项目中的 库所在文件夹比如 library文件夹 然后导入. 2 File-Project  Sructure  在Modu ...

  6. 04-树5 Complete Binary Search Tree

    这题也是第二次做,本想第一次做时参考的算法会和老师讲的一样,不想老师讲的算法用在这题感觉还不如思雪园友的算法(http://www.cnblogs.com/sixue/archive/2015/04. ...

  7. SecureCRT下的串口无法输入

    用串口配置交换机的时候,出现的问题: 用secureCRT建了一个串口COM1后,连接上开发板后,可以正确接受和显示串口的输出,但是按键输入无效. 解决方法: Session Options -> ...

  8. (转)关于java和web项目中的相对路径问题

    原文:http://blog.csdn.net/yethyeth/article/details/1623283 关于java和web项目中的相对路径问题 分类: java 2007-05-23 22 ...

  9. Code is not literature

    http://www.gigamonkeys.com/code-reading/ I have started code reading groups at the last two companie ...

  10. C++ Primer----一个关于 vector 的有趣的问题

    大家请看下面的代码,请问 输出结果是?? /** * @file vector-destroy.cc * @brief an interesting problem regarding vector ...