题目:https://vjudge.net/problem/UVA-1592
思路:
1.边输入边读,因为string类型数据的读入遇到空格就终止了,所以直接读入string,要一个字符一个字符得读,使用+将字符连接到字符串后,形成新的(可能含空格)的字符串,换行符有\n和\t
2.将字符串映射为数字,因为map中在使用count查找时,比较字符串比较费时,很可能会超时,转化成数字比较就容易很多。确定c1,c2列,遍历行,将对应的数字组成二元组,再映射到行数,具体参见代码
3.注意结构体的定义!!要会写!!
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; }
};
ac代码:
(写的有一丢丢乱...算了,暂时先这样吧,好懒QAQ)
#include <iostream>
#include <cmath>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#define maxn 105
#define inf 1e+9+10
using namespace std;
typedef long long ll;
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; }
};
char ch;
string s;
int n,m,r2,c1,c2,i,k;
map<string,int> ssin;
map<node,int> ans;
int a[10005][12];//记录整个表string转化成int后的情况
void solve()
{
for (c1 = 1; c1 <= m; c1++)
{
for (c2 = c1 + 1; c2<= m; c2++)
{
ans.clear();
for ( r2= 1; r2 <= n; r2++)
{
node p(a[r2][c1],a[r2][c2]);
if (!ans.count(p))//未找到
ans[p] = r2;
else
{
printf("NO\n");
printf("%d %d\n", ans[p], r2);
printf("%d %d\n", c1, c2);
return ;
}
}
}
}
printf("YES\n");
}
int main()
{
//freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);
ios::sync_with_stdio(false);
while (scanf("%d %d", &n, &m) != EOF)//n*m
{
bool flag = true;
ans.clear();
ssin.clear();
getchar();//读取回车
int num = 1;
//读入
for (i = 1; i <= n; i++)
{
k = 1;
s = "";
while (1)
{
ch = getchar();
if (ch == '\n' || ch == '\t' || ch == ',')//换行
{
if (!ssin.count(s))//无重复的
ssin[s] = num++;
a[i][k++] = ssin[s];//第k列的第i行个数编号为ssin[s]
s = "";
if (ch != ',')
break;
}
else
s += ch;
}
}
solve();
}
return 0;
}