UVA-1592 Database

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <vector>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <set>
 7 #include <map>
 8 
 9 using namespace std;
10 
11 
12 map<string,int> IDcache;
13 vector<string> Setcache;
14 
15 int ID(string x)
16 {
17     if(IDcache.count(x))  return IDcache[x];
18     Setcache.push_back(x);
19     return IDcache[x] = Setcache.size()-1;
20 }
21 
22 int main()
23 {
24     int rowSize,colSize;
25     while(cin >> rowSize >> colSize)
26     {
27         getchar();
28         vector<vector<int> > inputList;
29         vector<int> toBePushVec;
30         string toBePushStr;
31 
32         for(int i = 0;i < rowSize;i ++)
33         {
34             for(int j = 0;j < colSize;j ++)
35             {
36                 char tmpC;
37                 while((tmpC = getchar()) != ',' && tmpC != '\n')
38                 {
39                     toBePushStr += tmpC;
40                 }
41                 toBePushVec.push_back(ID(toBePushStr));
42                 toBePushStr.clear();
43             }
44             inputList.push_back(toBePushVec);
45             toBePushVec.clear();
46         }
47         
48         map<pair<int,int>,int> searchMap;
49         bool printFlag = false;
50         
51         for(int i = 0;i < colSize-1;i ++)
52         {
53             for(int j = i+1;j < colSize;j ++)
54             {
55                 for(int k = 0;k < rowSize;k ++)
56                 {
57                     auto iter = searchMap.find(make_pair(inputList[k][i],inputList[k][j]));
58                     if(iter == searchMap.end())
59                     {
60                         searchMap.insert(make_pair(make_pair(inputList[k][i],inputList[k][j]),k));
61                     }
62                     else
63                     {
64                         printFlag = true;
65                         cout << "NO" << endl;
66                         cout << iter->second + 1 << " " << k+1 << endl;
67                         cout << i+1 << " " << j+1 << endl;
68                         break;
69                     }
70                 }
71                 searchMap.clear();
72                 if(printFlag)
73                     break;
74             }
75             if(printFlag)
76                 break;
77         }
78         
79         if(! printFlag)
80             cout << "YES" << endl;
81     } 
82     return 0;
83 }

 

posted @ 2018-09-13 19:21  Asurudo  阅读(145)  评论(0编辑  收藏  举报