链接:https://codeforces.com/contest/1263/problem/B
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
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<set>
#include<algorithm>
#include<cstdlib>
using namespace std;
long long n,t,g,r,l,k,y,x,s=0;
char a[105][10];
int b[100001];
int ans[10001];
map<string,int>m;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
m.clear();
memset(ans,0,sizeof(ans));
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
if(ans[i]==1)
continue;
for(int j=i+1;j<=n;j++)
{
if(ans[j]==1)
continue;
if(a[i][0]==a[j][0])
{
if(a[i][1]==a[j][1]&&a[i][2]==a[j][2]&&a[i][3]==a[j][3])
{
s++;
b[s]=j;
ans[j]=1;
}
}
else
continue;
}
}
for(int i=1;i<=n;i++)
{
if(ans[i]==0)
{
m[a[i]]=1;
}
}
s=0;
for(int i=1;i<=n;i++)
{
if(ans[i]==1)
{
for(int j=0;j<4;j++)
{
char x=a[i][j];
int flag=0;
for(int k=0;k<=9;k++)
{
a[i][j]=k+'0';
if(m[a[i]]==0)
{
m[a[i]]=1;
flag=1;
s++;
break;
}
}
if(flag==0)
a[i][j]=x;
else
break;
}
}
}
cout<<s<<endl;
for(int i=1;i<=n;i++)
{
cout<<a[i]<<endl;
}
}
return 0;
}