1 Star 0 Fork 0

LLL2343 / vJudge

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1592.cpp 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
lll2343 提交于 2022-03-06 23:34 . 230
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
map<string,int> IDCache; // 将 串 映射到 ID
vector<string> StrCache; // 根据ID取string
const int MAX_I = 10005;
const int MAX_J = 12;
int ID(string x){
if(IDCache.count(x)){
return IDCache[x]; // 返回 字符串x 所对应的 ID(在StrCache里面的下标)
} else {
StrCache.push_back(x);
IDCache[x] = StrCache.size()-1;
return IDCache[x] ;
}
}
string Input(){
char ch;
string str;
int i=0;
while((ch=getchar()) && ch!=',' && ch!='\n'){
str += ch;
}
return str;
}
// int db[MAX_I][MAX_J];
int main(){
int n,m;
int db[4][4];
// freopen("./out.txt","w",stdout);
while(cin>>n>>m){
cin.ignore();
memset(db,-1,sizeof(db));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
string cur = Input();
// 现在得到目前的字符串
int id = ID(cur);
db[i][j] = id;
}
}
// 通过上述输入已经将string转换为int了
map<string,int > storeCache;
// 从俩列开始枚举
bool flag=true;
for(int i=0;i<m;i++){
if(!flag) break;
for(int j=i+1;j<m;j++){
if(!flag) break;
// 此时开始从列开始存map
for(int k=0;k<n;k++){
string cols = to_string(db[k][i])+","+to_string(db[k][j]);
auto iter = storeCache.find(cols);
if(/*map中包含该键值对*/ iter != storeCache.end()){
cout<<"NO\n";
cout<<(iter)->second+1<<" "<<k+1<<"\n"<<i+1<<" "<<j+1<<"\n";
flag = false;
break;
} else {
// 保存该键值对
storeCache[cols] = k;
}
}
}
storeCache.clear();
}
if(flag) cout<<"YES\n";
}
return 0;
}
1
https://gitee.com/lll2343/v-judge.git
git@gitee.com:lll2343/v-judge.git
lll2343
v-judge
vJudge
master

搜索帮助