UVa1262 - Password
2015-10-08 21:49
141 查看
不知道哪错了。。0.0
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cstdlib> #include <string> using namespace std; const int INF = ~0U >> 1; const int maxn = 7; char s1[maxn][maxn], s2[maxn][maxn]; string str[maxn]; int T, k, cnt = 0; void init() { memset(s1, 0, sizeof(s1)); memset(s2, 0, sizeof(s2)); for(int i = 0; i < maxn; ++i) str[i].clear(); return ; } int dfs(int n, char* ans) { if(n == 5) { ++cnt; if(cnt == k) { printf("%s\n", ans); return 1; } return 0; } for(int i = 0; i < str .size(); ++i) { ans = str [i]; if(dfs(n + 1, ans)) return 1; ans = 0; } } int main() { scanf("%d", &T); while(T--) { cnt = 0; init(); scanf("%d", &k); for(int i = 0; i < 6; ++i) scanf("%s", s1[i]); for(int i = 0; i < 6; ++i) scanf("%s", s2[i]); for(int i = 0; i < 5; ++i) { int cnt = 0; for(int j = 0; j < 6; ++j) for(int k = 0; k < 6; ++k) if(s1[j][i] == s2[k][i]) str[i].push_back(s1[j][i]); } // for(int i = 0; i < 5; ++i) cout << str[i] << endl; bool ok = true; for(int i = 0; i < 5; ++i) { unique(str[i].begin(), str[i].end()); sort(str[i].begin(), str[i].end()); if(str[i].size() == 0) ok = false; } if(!ok) { printf("NO\n"); continue; } char s[maxn] = {0}; if(!dfs(0, s)) printf("NO\n"); } return 0; }
相关文章推荐
- 1002. A+B for Polynomials
- 【Linux命令与工具】系统资源查看——free、uname、dmesg以及netstat
- 【SQL】事务
- C++ 面试(1)指针
- S3C2440上移植内核之编译Linux2.6.31出现问题
- DedeCms自定义字段调用长度截取方法
- Swift 细小知识点汇集
- 《TCP/IP详解 卷一:协议》读书笔记--IP选路
- Android 开发第七弹:简易时钟(秒表)
- 软件性能
- linux 初学者之进程控制
- Spring验证、数据绑定和类型转换
- 我的第一篇博客
- 1008. Elevator
- 用jquery写的”抽奖“小游戏的转盘。顺带选人
- (转)Render Path
- [LeetCode-234] Palindrome Linked List(回文链表、链表中间节点查找)
- Java 和Java虚拟机的关系
- MYSQL -- case when用法
- 1011. World Cup Betting