链接:

https://codeforces.com/contest/1263/problem/B

题意:

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?

思路:

n最大是10, 直接暴力修改

代码:

#include<bits/stdc++.h>
using namespace std; int main()
{
int t;
cin >> t;
while(t--)
{
int n;
string s[10];
map<string, int> Mp;
cin >> n;
for (int i = 0;i < n;i++)
cin >> s[i], Mp[s[i]]++;
int ans = 0;
for (int i = 0;i < n;i++)
{
if (Mp[s[i]] > 1)
{
ans++;
Mp[s[i]]--;
for (int j = 0;j < 10;j++)
{
s[i][0] = j+'0';
if (Mp[s[i]] == 0)
break;
}
Mp[s[i]]++;
}
}
cout << ans << endl;
for (int i = 0;i < n;i++)
cout << s[i] << endl;
} return 0;
}

最新文章

  1. React对话框组件实现
  2. MySQL 主键冲突,无法插入数据
  3. linux 命令小例
  4. 23讲 URL2
  5. linux命令——scp
  6. 4.ICMP协议,ping和Traceroute
  7. Spring+SpringMVC+MyBatis+easyUI整合基础篇(六)maven整合SSM
  8. Angular2.js——主从结构
  9. Cloudstack网络分析-基本网络
  10. C++语言中的类型(一)
  11. 【Linux 操作系统】vim编辑器配置及常用命令
  12. SQL随记(四)
  13. js获取当前时间并实时刷新
  14. Linux系统本地yum源环境配置记录
  15. golang切片数据结构解释
  16. 魔兽私服TrinityCore 运行调试流程
  17. 在mac环境下用QT使用OpenGL,glut,glfw
  18. Python - TypeError: unicode argument expected, got &#39;str&#39;
  19. Java Spring中@Query中使用JPQL LIKE 写法
  20. MongoDB成为最受开发人员期待的数据库系统

热门文章

  1. [转帖]spring、springMvc、springBoot和springCloud的联系与区别
  2. 【译】RAID的概念和RAID对于SQL性能的影响
  3. Springboot Actuator之十一:actuator transaction
  4. Android -- SEGV_MAPERR,SEGV_ACCERR
  5. Mysql系列(六)—— MySQL索引介绍
  6. Flink基本的API
  7. javascript 对象之hasOwnProperty()方法
  8. 安装多个jdk导致eclipse打不开问题
  9. php批量检查https证书有效期
  10. VS 对话框控件的Tab顺序问题