栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3865 Database

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3865 Database

#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<iostream>using namespace std;struct Node{ char s[90]; int r,c;}p[100005];char s[20000],t[290];int n,m,id;void gao(int a){ int len=strlen(s),last=0,fi=0; for(int i=0;i<=len;i++) if(i==len||s[i]==',') { int sz=0; for(int j=last;j<i;j++)t[sz++]=s[j]; t[sz]=''; strcpy(p[id].s,t); p[id].r=a; p[id++].c=fi++; last=i+1; }}bool cmp(const Node &p1,const Node &p2){ return strcmp(p1.s,p2.s)<0;}int rk[21005][11],c1,c2,g[20010];bool cmp2(const int &a,const int &b){ if(rk[a][c1]!=rk[b][c1])return rk[a][c1]<rk[b][c1]; return rk[a][c2]<rk[b][c2];}int main(){ while(scanf("%d%d",&n,&m)==2) { getchar(); id=0; for(int i=0;i<n;i++) { gets(s); gao(i); } sort(p,p+id,cmp); int M=1; rk[p[0].r][p[0].c]=1; for(int i=1;i<id;i++) if(strcmp(p[i].s,p[i-1].s)!=0) rk[p[i].r][p[i].c]=++M; else rk[p[i].r][p[i].c]=M; for(int i=0;i<n;i++) g[i]=i; bool ans=1; for(c1=0;c1<m && ans;c1++) for(c2=c1+1;c2<m;c2++) { sort(g,g+n,cmp2); for(int i=1;i<n;i++) if(rk[g[i]][c1]==rk[g[i-1]][c1] && rk[g[i]][c2]==rk[g[i-1]][c2]) { printf("NOn%d %dn%d %dn",g[i]+1,g[i-1]+1,c1+1,c2+1); ans=0; break; } } if(ans)puts("YES"); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367468.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号