题意:
给出n行 m列字符串
请你找出某两行两列的相同
如果有不同就输出no 再输出两行的行数 再输出两列的列数
题解:
输入的时候先将字符串映射到一个数字保存成一个二维数组
然后枚举两列,判断哪两行满足题意
这里的stl用的很活 可以多看看
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,long long> pll;
const int INF = 0x3f3f3f3f;
const int maxn=100+5;
map<string, int> IDcache;
map<pair<int, int>, int> NewIDcache;
int a[11000][20];
int n, m;
void match()
{
int x, y;
for (int c1 = 0; c1 < m-1; c1++)
{
for (int c2 = c1 + 1; c2 < m; c2++)
{
for (int r = 0; 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)] + 1 << " " << r + 1 << endl;
cout << c1 + 1 << " " << c2 + 1 << endl;
return;
}
}
NewIDcache.clear();
}
}
cout << "YES" << endl;
}
int main()
{
freopen("in.txt","r",stdin);
//freopen("database.in","r",stdin);
//freopen("database.out","w",stdout);
while (cin >> n >> m)
{
int t = 1;
getchar();
string str;
IDcache.clear();
NewIDcache.clear();
for (int i = 0; i < n; i++)
{
int count = 0;
str.clear();
getline(cin, str);
int l = str.length();
string s;
for (int j = 0; j < l; j++)
{
if (str[j] != ',') s = s + str[j];
if (str[j] == ',' || j == l-1)
{
if (!IDcache.count(s)) IDcache[s] = t++;
a[i][count++] = IDcache[s];
s.clear();
}
}
}
match();
}
}