B. PIN Codes

14 篇文章 0 订阅

output

standard output

A PIN code is a string that consists of exactly 44 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 nn (2≤n≤102≤n≤10) bank cards, the PIN code of the ii-th card is pipi.

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 nn codes would become different.

Formally, in one step, Polycarp picks ii-th card (1≤i≤n1≤i≤n), then in its PIN code pipi selects one position (from 11 to 44), 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 tt (1≤t≤1001≤t≤100) — the number of test cases in the input. Then test cases follow.

The first line of each of tt test sets contains a single integer nn (2≤n≤102≤n≤10) — the number of Polycarp's bank cards. The next nn lines contain the PIN codes p1,p2,…,pnp1,p2,…,pn — one per line. The length of each of them is 44. All PIN codes consist of digits only.

Output

Print the answers to tt test sets. The answer to each set should consist of a n+1n+1 lines

In the first line print kk — the least number of changes to make all PIN codes different. In the next nn 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

Copy

3
2
1234
0600
2
1337
1337
4
3139
3139
3139
3139

output

Copy

0
1234
0600
1
1337
1237
3
3139
3138
3939
6139

题意就是让你把他们这n个数变成不重复的只能修改一位数字

问最少修改几次

思路:如果重复直接让最后一位改成不同即可

#include<bits/stdc++.h>
using namespace std;
int h[23];
int main() {
	int t;
	scanf("%d", &t);
	while(t--) {
		int n;map<int,int>A;
		map<int,int>B;
		scanf("%d", &n);
		int ans = 0;
		for(int i = 1;i <= n;++i) {
			scanf("%d", &h[i]);
			A[h[i]]++;
			if(A[h[i]] >= 2) {
				ans++;
			}
			B[h[i]%10]++;
		}
		printf("%d\n", ans);
		for(int i = 1;i <= n;++i) {
			if(A[h[i]] >= 2) {
				A[h[i]]--;
				int g = h[i];
				int flag = 0;
					int h1 = g%10;g/=10;
					int h2 = g%10;g/=10;
					int h3 = g%10;g/=10;
					int h4 = g%10;
					for(int i = 0;i <= 9;++i) {
						if(B[i] == 0) {
							printf("%d%d%d%d\n", h4,h3,h2,i);
							B[i] = 1;flag = 1;
							break;
						}
					}
			}
			else {
				printf("%04d\n", h[i]);
			}
		}
		
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-lyslyslys

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值