博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CodeForces 1263B --- PIN Codes】
阅读量:2038 次
发布时间:2019-04-28

本文共 2069 字,大约阅读时间需要 6 分钟。

【CodeForces 1263B --- PIN Codes】

Description

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.

Sample Input

3

2
1234
0600
2
1337
1337
4
3139
3139
3139
3139

Sample Output

0

1234
0600
1
1337
1237
3
3139
3138
3939
6139

AC代码:

#include 
using namespace std;#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)#define endl '\n'string s[20];bool vis[20];int n,x;int main(){
SIS; int T,x; cin >> T; while(T--) {
cin >> n; map
mp; for(int i=0;i
> s[i]; mp[s[i]]++; } int cnt=0; for(int i=0;i

转载地址:http://jiyof.baihongyu.com/

你可能感兴趣的文章
多线程
查看>>
MVC、MVP、MVVM之间的关系
查看>>
计算机网络--HTTP协议(二)
查看>>
Spring 手动提交事务
查看>>
代码重构(一):函数重构规则
查看>>
IP地址分类
查看>>
Spring总结之注解(2)
查看>>
Maven常用命令大全与pom文件讲解
查看>>
Java和JavaScript中使用Json方法大全
查看>>
Ubuntu14.04下安装docker
查看>>
ubuntu下安装nginx
查看>>
Linux 更改文件名
查看>>
Linux下安装Elasticsearch5.X
查看>>
linux命令ps aux|grep xxx详解
查看>>
MySQL常见问题
查看>>
Spring Boot 入门之缓存和 NoSQL 篇(四)
查看>>
使用Docker高效搭建开发环境
查看>>
微服务下的数据架构
查看>>
Nginx 容器教程
查看>>
linux下的命令: sudo ln -s 源文件 目标文件
查看>>