紫書UVa1592

weixin_46273288發表於2020-12-07

在這裡插入圖片描述

#include <vector>
#include <map>
#include <sstream>
#include <string>
#include<iostream>
#include<cstdio>
#include <algorithm>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
int getID(vector<string>& strCache, map<string, int>& mapStr,string&x)
{
	if (mapStr.count(x) > 0)
	{
		return mapStr[x];
	}
	strCache.push_back(x);
	return mapStr[x] = strCache.size() - 1;
}
int main()
{
	int n, m;
	while (cin >> n >> m)
	{
		vector<string> stringCache;
		map<string, int>mapString;
		cin.get();
		vector<vector<string>>database(n);
		for (int i = 0; i < n; ++i)
		{
			string temp;
			for(int j = 0;j < m - 1;++j)
			{
				getline(cin, temp, ',');
				database[i].push_back(move(temp));
			}
			getline(cin, temp);
			database[i].push_back(move(temp));
		}
		int isfind = 0;
		int c1, c2, r1, r2;
		for (int i = 0; i < m; ++i)
		{
			for (int j = i + 1; j < m; ++j)
			{
				
				map<pair<int, int>,int> rep;
				for (int k = 0; k < n; ++k)
				{
					;
					if (rep.count(make_pair(getID(stringCache, mapString, database[k][i]), getID(stringCache, mapString, database[k][j])))> 0)
					{
						isfind = 1;
						r2 = k + 1;
						r1 = rep[make_pair(getID(stringCache, mapString, database[k][i]), getID(stringCache, mapString, database[k][j]))] + 1;
						break;
					}
					rep[make_pair(getID(stringCache, mapString, database[k][i]), getID(stringCache, mapString, database[k][j]))] = k;
				}
				if (isfind == 1)
				{
					c2 = j + 1;
					break;
				}
			}
			if (isfind == 1)
			{
				c1 = i + 1;
				break;
			}
		}
		if (isfind == 1)
		{
			cout << "NO" << endl;
			cout << r1 << ' ' << r2 << endl;
			cout << c1 << ' ' << c2 << endl;
		}
		else
		{
			cout << "YES" << endl;
		}
	}
}

相關文章