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 水题的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  5. 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 ...

  6. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  7. 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 ...

  8. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

  9. 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 ...

随机推荐

  1. Complete_NGINX_Cookbook

    Complete NGINX Cookbook 下载地址:Complete NGINX Cookbook

  2. 字段明明存在,用Web API使用该字段进行查询报错?

    我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...

  3. Jerome: Vulnhub Walkthrough

    nmap 扫描探测: ╰─ nmap -p1-65535 -sV -A -O -sT 10.10.202.135Starting Nmap 7.70 ( https://nmap.org ) at 2 ...

  4. LeetCode刷题191218

    好多天没有更新了,今天有空,刷一道. 算法第5题 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad"输出: ...

  5. Cocos2d-x 3.2 的内存管理详解

    目标读者:了解 Cocos2d-x 中的节点以及节点树,了解引用计数,了解游戏主循环等概念. 本文首先介绍 Cocos2d-x 3.2 中内存管理的作用,以及各个作用的应用.借由通俗易懂的解释来了解内 ...

  6. uiautomatorviewer 报错 Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!

    在进行自动化时经常需要使用到 uiautomatorviewer获取控件的各个属性,然后在脚本中通过各个控件的属性来操作. 如果使用的是uiautomator2的话,一般都是使用weditor这个来查 ...

  7. 池化技术(一)Druid是如何管理数据库连接的?

    基于依赖程序的版本信息:druid:1.1.16               驱动程序mysql-connector-java:8.0.17 下一篇:HikariCP是如何管理数据库连接的 零.类图& ...

  8. JavaScript-----9.函数

    1.函数的使用 1.1 声明函数和调用函数 //1.声明函数 //function 函数名() { // //函数体 //} function sayHi() { console.log('hi~') ...

  9. [译]Vulkan教程(09)窗口表面

    [译]Vulkan教程(09)窗口表面 Since Vulkan is a platform agnostic API, it can not interface directly with the ...

  10. Linux 指令学习

    查询java安装地址 which java ls -lrt /bin/java ls -lrt /etc/alternatives/java # 如果已经配好,则echo $JAVA_HOME 更改环 ...