UVa 1592

练习一个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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值