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 ...
随机推荐
- Computer: Use the mouse to open the analog keyboard
Xx_Introduction Please protection,respect,love,"China's Internet Security Act"! For learni ...
- 基于Moya、RxSwift和ObjectMapper优雅实现REST API请求
在Android开发中有非常强大的 Retrofit 请求,结合RxJava可以非常方便实现 RESTful API 网络请求.在 iOS开发中也有非常强大的网络请求库 Moya ,Moya是一个基于 ...
- C#&.Net干货分享- 构造SMSWebChineseApi对接第三方短信平台
你们想要的短信对接,要舍得点钱哦.... /// <summary> /// http://sms.webchinese.cn/api.shtml /// </summa ...
- s3c2440裸机-代码重定位(1.重定位的引入,为什么要代码重定位)
1.重定位的引入(为什么要代码重定位) 我们知道s3c2440的cpu从0地址开始取指令执行,当从nor启动时,0地址对应nor,nor可以像内存一样读,但不能像内存一样写.我们能够从nor上取指令执 ...
- mysql在本地已经启动,但是在网页上不能直接访问的解决
1.将mysql文件下的my.ini中的路径代码 # 设置mysql的安装目录 basedir=E:/Develop/mysql # 设置mysql数据库的数据的存放目录 datadir=E:/Dev ...
- 微信小程序之POST请求
最近写自己的小项目时,遇到一个问题很头疼,几天了一直解决不了 背景: 前端调用java接口,存中文乱码 但是该接口所要存数据的表在B服务器同样的数据库里面,调用B服务器的接口存中文就没问题 起初以为是 ...
- 用了 Lambda 之后,发现可以忘记设计模式了
设计模式是过去的一些好的经验和套路的总结,但是好的语言特性可以让开发者不去考虑这些设计模式.面向对象常见的设计模式有策略模式.模板方法.观察者模式.责任链模式以及工厂模式,使用Lambda表达式(函数 ...
- mjml - 如何快速编写响应式电子邮件?
一.背景 以前做项目碰到发邮件的需求,邮件模板的编辑就是一件头疼的事.因为虽说邮件是支持 HTML 的,但是确是 HTML 子集程度的支持,所以存在必须通过 <table> 排版的恶心之处 ...
- 工作笔记 之 Linux服务搭建
No.1 linux环境下安装nginx步骤 Nginx (engine x) 是一款轻量级的Web 服务器.反向代理服务器.电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行. ...
- Python 关于 pip 部分相关库的安装
下文中“:”后面安装的安装语句需要打开 cmd (命令提示符),在 cmd 中输入. 示例: 在搜索框输入 cmd,单机命令提示符: 然后输入安装语句,按回车键: 因为我之前已经装过了,所以这里显示的 ...