Advertisement
_rashed

UVA 1592 Database

Feb 23rd, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8. map<pair<string,string>,int> mps[11][11];
  9.  
  10. int main()
  11. {
  12.     ios_base::sync_with_stdio(false);
  13.     cin.tie(NULL);
  14.     cout.tie(NULL);
  15.     int n,m;
  16.     while(cin >> n >> m) {
  17.         string x;
  18.         getline(cin,x);
  19.         //cout << "x is " << x << "\n";
  20.         pair<int,int> ans_r = {-1,-1};
  21.         pair<int,int> ans_c = {-1,-1};
  22.         for(int r = 1; r <= n; r++) {
  23.             string row = "";
  24.             getline(cin,row);
  25.             int idx = 0;
  26.             string cols[11];
  27.             for(int c = 1; c <= m; c++) {
  28.                 string col = "";
  29.                 for(; idx < row.size(); idx++) {
  30.                     if(row[idx] != ',')
  31.                         col += row[idx];
  32.                     else
  33.                         break;
  34.                 }
  35.                 idx++;
  36.                 //cout << col << "\n";
  37.                 cols[c] = col;
  38.                 /*if(mp.find(col) == mp.end()) {
  39.                     mp[col] = {r,c};
  40.                 }
  41.                 else {
  42.                     if(mp[col].first != r) {
  43.                         ans_r = {mp[col].first,r};
  44.                         ans_c = {mp[col].second,c};
  45.                     }
  46.                 }*/
  47.             }
  48.             for(int c1 = 1; c1 < m; c1++) {
  49.                 for(int c2 = c1+1; c2 <= m; c2++) {
  50.                     pair<string,string> curr = {cols[c1],cols[c2]};
  51.                     if(mps[c1][c2].find(curr) != mps[c1][c2].end()) {
  52.                         ans_r = {mps[c1][c2][curr],r};
  53.                         ans_c = {c1,c2};
  54.                     }
  55.                     else {
  56.                         mps[c1][c2][curr] = r;
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.         for(int i = 1; i < m; i++) {
  62.             for(int j = i+1; j <= m; j++) {
  63.                 mps[i][j].clear();
  64.             }
  65.         }
  66.         if(ans_r.first == -1) {
  67.             cout << "YES\n";
  68.         }
  69.         else {
  70.             cout << "NO\n";
  71.             cout << ans_r.first << " " << ans_r.second << "\n";
  72.             cout << ans_c.first << " " << ans_c.second << "\n";
  73.         }
  74.     }
  75.     return 0;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement