练习一个STL的题,感觉蛮有难度的,在一些这种简单的STL操作应用,显然我还不够熟练啊。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
int n,m;
char a[100];
string s;
map<string,int> p;//把字符串对应成数字编号
struct node
{
int x,y;
node(int x,int y):x(x),y(y) { }
bool operator < (const node& r) const {return x<r.x||x==r.x&&y<r.y;}
};
vector<int> row[10050];//每行的对应着的有m个字符串的编号
vector<string> sta;
map<node,int> data;//c1,c2对应着r值
int ID_alloc(string ss)
{
if(p.count(ss)) return p[ss];
sta.push_back(ss);
return p[ss]=sta.size()-1;
}
void slove()
{
for(int c1=0;c1<m;c1++)
{
for(int c2=c1+1;c2<m;c2++)
{
data.clear();
for(int r=0;r<n;r++)
{
int x=row[r][c1];
int y=row[r][c2];
node pp(x,y);
if(!data.count(pp)) data[pp]=r;
else
{
printf("NO\n");
printf("%d %d\n%d %d\n",data[pp]+1,r+1,c1+1,c2+1);
return ;
}
}
}
}
printf("YES\n");
return ;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
string st;
char ch=getchar();
for(int i=0;i<n;i++)
{
for(;;)
{
ch=getchar();
if(ch=='\n'||ch=='\r')
{
if(!st.empty()) row[i].push_back(ID_alloc(st));
st.clear(); break;
}
if(ch!=',') st+=ch;
else
{
row[i].push_back(ID_alloc(st));
st.clear();
}
}
}
slove();
for(int i=0;i<10050;i++)
row[i].clear();
sta.clear();
p.clear();
}
return 0;
}