PIN Codes CodeForces

编程入门 行业动态 更新时间:2024-10-09 03:28:11

<a href=https://www.elefans.com/category/jswz/34/1767540.html style=PIN Codes CodeForces"/>

PIN Codes CodeForces

一、内容

A PIN code is a string that consists of exactly 4digits. 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 ncodes 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 ttest sets. The answer to each set should consist of a n+1linesIn the first line print k— the least number of changes to make all PIN codes different. In the next nlines 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.

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

二、思路

  • 由于只有10个数字,所以只需要随便修改一位上面的数字就可以让n个数字不同。

三、代码

#include <cstdio>
#include <map>
#include <cstring>
#include <iostream>
using namespace std;
int t, n;
string str[15];
int main() {scanf("%d", &t);while (t--) {map<string, int> mp;scanf("%d", &n);for (int i = 1; i <= n; i++) {cin >> str[i];mp[str[i]]++;}int ans = 0;for (int i = 1; i <= n; i++) {if (mp[str[i]] == 1) continue;ans++;mp[str[i]]--;//替换字符for (int j = 0; j <= 9; j++) {str[i][0] = '0' + j;if (mp[str[i]] == 0) {mp[str[i]]++;break;}} }cout << ans << endl; for (int i = 1; i <= n; i++) {cout << str[i] << endl;}} return 0;
}

更多推荐

PIN Codes CodeForces

本文发布于:2024-02-13 22:23:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1760926.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PIN   Codes   CodeForces

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!