Codeforces Round #603 (Div. 2) B. PIN Codes 水题
B. PIN Codes
A PIN code is a string that consists of exactly 4 digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.
Polycarp has n (2≤n≤10) bank cards, the PIN code of the i-th card is pi.
Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all n codes would become different.
Formally, in one step, Polycarp picks i-th card (1≤i≤n), then in its PIN code pi selects one position (from 1 to 4), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different.
Polycarp quickly solved this problem. Can you solve it?
Input
The first line contains integer t (1≤t≤100) — the number of test cases in the input. Then test cases follow.
The first line of each of t test sets contains a single integer n (2≤n≤10) — the number of Polycarp's bank cards. The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4. All PIN codes consist of digits only.
Output
Print the answers to t test sets. The answer to each set should consist of a n+1 lines
In the first line print k — the least number of changes to make all PIN codes different. In the next n lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them.
Example
input
3
2
1234
0600
2
1337
1337
4
3139
3139
3139
3139
output
0
1234
0600
1
1337
1237
3
3139
3138
3939
6139
题意
给了你n个4位数的pin code,你每次可以修改一个数的一个位置,问你最少修改多少次,可以使得每个数都不一样。
题解
视频题解 https://www.bilibili.com/video/av77514280/
数据范围最多为10,所以每个pin code最多修改一个位置就可以了,我们首先给所有字符串标记出现过没有,重复的就把他修改成没有出现过的位置。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 15;
string s[15];
int n,ans;
map<string,int>H;
void change(int x){
	H[s[x]]--;
	for(int i=0;i<s[x].size();i++){
		char ori = s[x][i];
		for(int j=0;j<10;j++){
			char c = '0'+j;
			s[x][i]=c;
			if(!H[s[x]]){
				ans++;
				H[s[x]]=1;
				return;
			}
		}
		s[x][i]=ori;
	}
}
void solve(){
	H.clear();
	ans = 0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		H[s[i]]++;
	}
	//sort(s,s+n);
	for(int i=0;i<n;i++){
		if(H[s[i]]>1){
			change(i);
		}
	}
	cout<<ans<<endl;
	for(int i=0;i<n;i++){
		cout<<s[i]<<endl;
	}
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}Codeforces Round #603 (Div. 2) B. PIN Codes 水题的更多相关文章
- Codeforces Round #603 (Div. 2) B. PIN Codes
		链接: https://codeforces.com/contest/1263/problem/B 题意: A PIN code is a string that consists of exactl ... 
- Codeforces Round #603 (Div. 2) A. Sweet Problem 水题
		A. Sweet Problem the first pile contains only red candies and there are r candies in it, the second ... 
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
		Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ... 
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
		Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ... 
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
		A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ... 
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
		A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ... 
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
		A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ... 
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
		A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ... 
- Codeforces Round #335 (Div. 2) B. Testing Robots 水题
		B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ... 
随机推荐
- Hyper-V “SP2019SER”无法更改状态。操作失败,错误代码为“32788”。
			卸载Hyper-V,然后重装,再重启已有的Hyper-V服务器,报错如下: 尝试启动选定的虚拟机时出错.“SP2019SER”无法更改状态. 原因:卸载后导致虚拟网卡出现问题导致的. 解决办法: 右击 ... 
- gitlab忘记密码如何重置
			gitlab web登入密码忘记以后可以用如下方式修改密码shell>cd /home/git/gitlabshell> su gitshell>bundle exec rails ... 
- TCP 三次握手与四次挥手
			TCP是什么 TCP(Transmission Control Protocol 传输控制协议)是一种面向连接(连接导向)的.可靠的. 基于IP的传输层协议. TCP有6种标示: ... 
- TP事物的写法
			Db::startTrans(); try{ Db::commit(); } catch (\Exception $e) { Db::rollback(); } use think\Db; publi ... 
- Database mirroring connection error 4 'An error occurred while receiving data: '10054(An existing connection was forcibly closed by the remote host.)
			公司一SQL Server镜像发生了故障转移(主备切换),检查SQL Server镜像发生主备切换的原因,在错误日志中发现下面错误: Date 2019/8/31 14:09:17 ... 
- Qt 信号和槽异常:  QObject::connect: No Such slot baseClassName::subClassfunction() in ......
			2019-08-14起笔 小熊的情况描述: 父类A继承自QWidget,所以父类A自动添加了Q_OBJECT. 子类B继承自父类A,子类B没有添加Q_OBJECT.在子类B中给动态创建的控件添加事件 ... 
- Python 变量与运算符
			变量 基本概念: 1. 变量,名字,数据的唯一标识2.变量命名: 字母.数字.下划线: 不能以数字开头: 区分大小写: 不能使用保留字和关键字: 命名要有意义:(多个单词时,推荐使用下划线连接) 3. ... 
- js获取input checkbox的选中值
			HTML代码: <form action="/test/action" method="get"> <input type="che ... 
- doc 如何在指定的位置打印字符和颜色
			编程:在屏幕中间分别显示绿色,绿底红色,白底蓝色的字符串weclome to masm! B8000H~BFFFFH共32KB 的空间,为80*25彩色字符模式的显示缓冲区. 在80*25彩色字符模式 ... 
- 某小公司RESTful、共用接口、前后端分离、接口约定的实践
			作者:邵磊 juejin.im/post/59eafab36fb9a045076eccc3 前言 随着互联网高速发展,公司对项目开发周期不断缩短,我们面对各种需求,使用原有对接方式,各端已经很难快速应 ... 
