Password UVA - 1262

按照紫书的思路,首先找出对应的每列相同的字母,将这些字母分别存储之后,计算对应的数量,然后输出即可,具体实现见如下代码:

#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;

int main(){
	int T,K;
	cin >> T;
	while (T--){
		cin >> K;
		char first[6][5];
		char second[6][5];
		for (int i = 0; i < 6; i++){
			for (int j = 0; j < 5; j++){
				cin >> first[i][j];
			}
		}
		for (int i = 0; i < 6; i++){
			for (int j = 0; j < 5; j++){
				cin >> second[i][j];
			}
		}
		set<char> v[5];
		for (int j = 0; j < 5; j++){
			for (int ind1 = 0; ind1 < 6; ind1++){
				for (int ind2 = 0; ind2 < 6; ind2++){
					if (first[ind1][j] == second[ind2][j]){
						v[j].insert(first[ind1][j]);
						break;
					}
				}
			}
		}
		int amount[6];
		bool flag = false;
		amount[5] = 1;
		for (int i = 4; i >= 0; i--){
			amount[i] = amount[i + 1] * v[i].size();
			if (amount[i] == 0){
				flag = true;
				break;
			}
		}
		if (K> amount[0]||flag){
			cout << "NO\n";
			continue;
		}
		int cur = 0;
		set<char>::iterator j;
		for (int i = 0; i < 5; i++){
			for (j = v[i].begin(); j != v[i].end(); j++){
				if (cur + amount[i + 1] < K){
					cur += amount[i + 1];
				}
				else break;
			}
			cout << *j;
		}
		cout << endl;
	}
	return 0;
}

/*
3
ABDFK
OCOOO
ODOOO
OOOOO
OOOOO
OOOOO
ABDFK
ECEEE
EDEEE
EEEEE
EEEEE
EEEEE
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值