Codeforces Round #603 (Div. 2) B. PIN Codes 水题
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 水题的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- 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 ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- 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 ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
- 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 ...
随机推荐
- linux下通过命令连接wifi
故事背景:我司是做新零售的,机器支持4G.wifi.网线,可能会涉及到网络的切换和连接 项目需求:用户在web端输入wifi名称和密码,客户端可以通过服务端下发的信息进行连接 技术调研:之前提到过nm ...
- 【计算机网络】ISO/OSI 网络体系结构
ISO/OSI 网络体系结构 计算机网络是相当复杂的系统,相互通信的两个计算机系统必须高度协调才能正常工作.为了设计这样复杂的计算机网络,人们提出了将网络分层的方法.分层可将庞大而复杂的问题转换为若干 ...
- Oracle DB Time
Oracle DB Time是Oracle数据库在时间维度上剖析性能的一个重要指标,通过逐级分解该指标,定位到浪费资源或者资源争用的首要事件上,从而通过减少等待以及最小化每个请求的使用资源来达到优化的 ...
- s3c2440裸机-异常中断(一. 异常、中断的原理与流程)
1.异常中断概述 在arm架构的处理器中,cpu有7中工作模式,2中工作状态. 1.CPU模式(Mode): 7种Mode: 除了usr/sys,其他5种都是异常模式.我们知道中断属于异常的2中,中断 ...
- 5 其他命令-学习目标以及find命令的基本使用
.caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...
- nginx基础(3)
目录 HTTP首部 1.通用首部 2.请求首部 2.1 必有首部 2.2 条件请求首部 2.3 安全相关首部 3.响应首部 3.1 必有首部 3.2 协商首部 3.3 安全相关首部 4.实体首部 4. ...
- Java死锁演示
Java死锁演示 在线程中嵌套获取锁导致死锁.思路,尽量不要嵌套获取锁. package com.mozq.demo.demo; public class DeadLockDemo { private ...
- nginx 反向代理之 proxy_pass
格式很简单: proxy_pass URL; 其中URL包含:传输协议(http://, https://等).主机名(域名或者IP:PORT).uri. 示例如下: proxy_pass http: ...
- stars-one的原创工具——APK签名验证破解工具
ASCTool APk签名验证破解工具 APK Signature Crack Tool 本工具只对那些仅通过 PackageManager.getPackageInfo().signatures 来 ...
- C# 调用POST请求
public static void PostUrl_Ex(string url, string postData) { try { //对于提交内容中的中文使用UrlEncode方式编码 发送 // ...