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. VueUI -- iView4.0简单使用

    一.iView(View UI) 1.简介 官网:https://www.iviewui.com/ 仓库:https://github.com/view-design/ViewUI iView 与 V ...

  2. C lang: The caracter reverse

    Ax_Code #include<stdio.h> int main(void) { int i; char string[7] = {"mrsoft"}; char ...

  3. Android 时间对话框 TimePickerDialog

    private int hourOfDay, minute; @Override protected void onCreate(Bundle savedInstanceState) { super. ...

  4. 梁敬彬老师的《收获,不止SQL优化》,关于如何缩短SQL调优时间,给出了三个步骤,

    梁敬彬老师的<收获,不止SQL优化>,关于如何缩短SQL调优时间,给出了三个步骤, 1. 先获取有助调优的数据库整体信息 2. 快速获取SQL运行台前信息 3. 快速获取SQL关联幕后信息 ...

  5. MySQL数据库~~~~ 完整性约束

    1. not null 与 default not null : 不可空 default : 默认值 例: create table t1(id int not null default 2); 2. ...

  6. a是什么??

    //解决Linux下默认中文字体乱码问题 QFont font("simsun", 11, QFont::Normal, false); a.setFont(font);

  7. MyBatis核心对象之StatementHandler

    MyBatis核心对象之StatementHandler StatementHandler ResultHandler ParameterHandler Executor org.apache.iba ...

  8. 用了 Lambda 之后,发现可以忘记设计模式了

    设计模式是过去的一些好的经验和套路的总结,但是好的语言特性可以让开发者不去考虑这些设计模式.面向对象常见的设计模式有策略模式.模板方法.观察者模式.责任链模式以及工厂模式,使用Lambda表达式(函数 ...

  9. react+ant-mobile+lib-flexible构建移动端项目适应设计图尺寸(750)

    使用lib-flexible在react中先安装 npm install lib-flexible --save 因为插件使用的是rem适配,所以安装两个插件 npm install postcss- ...

  10. 38条技巧优化PHP代码,来复习总结下吧

    1.如果一个方法能被静态,那就声明他为静态的,速度可提高1/4; 2.echo的效率高于print,因为echo没有返回值,print返回一个整型; 3.在循环之前设置循环的最大次数,而非在在循环中; ...