链接:

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;
}

Codeforces Round #603 (Div. 2) B. PIN Codes的更多相关文章

  1. 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 code ...

  2. 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 ...

  3. Codeforces Round #603 (Div. 2)

    传送门 感觉脑子还是转得太慢了QAQ,一些问题老是想得很慢... A. Sweet Problem 签到. Code /* * Author: heyuhhh * Created Time: 2019 ...

  4. Codeforces Round #603 (Div. 2) E. Editor 线段树

    E. Editor The development of a text editor is a hard problem. You need to implement an extra module ...

  5. Codeforces Round #603 (Div. 2) E. Editor(线段树)

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...

  6. Codeforces Round #603 (Div. 2) (题解)

    A. Sweet Problem (找规律) 题目链接 大致思路: 有一点瞎猜的,首先排一个序, \(a_1>a_2>a_3\) ,发现如果 \(a_1>=a_2+a_3\) ,那么 ...

  7. Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集

    D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...

  8. Codeforces Round #603 (Div. 2) D. Secret Passwords(并查集)

    链接: https://codeforces.com/contest/1263/problem/D 题意: One unknown hacker wants to get the admin's pa ...

  9. Codeforces Round #603 (Div. 2) C. Everyone is a Winner! (数学)

    链接: https://codeforces.com/contest/1263/problem/C 题意: On the well-known testing system MathForces, a ...

随机推荐

  1. Vue父组件如何调用子组件(弹出框)中的方法的问题

    如果子组件是一个弹出框,只有在触发某个点击事件时弹出框才能出现(也就是说在父组件中的子组件使用上用了v-if),那在父组件上如果不点击弹出框是不能获取到$ref的. 原因就是:引用指向的是子组件创建的 ...

  2. 1083 是否存在相等的差 PAT (Basic Level)

    题目链接: https://pintia.cn/problem-sets/994805260223102976/problems/994805260780945408 分析: 将某个差值的次数存在数组 ...

  3. java中各种常见的异常

    一.各种常见的异常 在上一节中程序如果你注意留意,程序抛出的异常是:java.lang.ArithmeticException.这个异常是在lang包中已经定义的.在lang包中还定义了一些我们非常常 ...

  4. DotnetSpider爬虫简单示例 net core

    文章地址 https://blog.csdn.net/sD7O95O/article/details/78097556 安装爬虫框架  NUGET 安装DotnetSpider 创建HTTP协议数据包 ...

  5. 静下心来学jquery的用法

    http://blog.csdn.net/xiaojun1288/article/details/6803552

  6. @Valid注解的使用springmvc pojo校验

    @Valid注解用于校验,所属包为:javax.validation.Valid. ① 首先需要在实体类的相应字段上添加用于充当校验条件的注解,如:@Min,如下代码(age属于User类中的属性): ...

  7. Options of the DB storage of prometheus

    参考: // Options of the DB storage. type Options struct { // The timestamp range of head blocks after ...

  8. 【方法论】5WHY分析法

    一.概述 所谓“5WHY”分析法,又称“5问法”,就是连续反复使用5次“为什么”方式自问,以打破砂锅问到底方式寻找问题的根本原因的方法.“5WHY”不限定必须或只做5次为什么的提问,以找到问题根因为准 ...

  9. vue生成pdf

    主要参考 https://blog.csdn.net/qq_37880968/article/details/94626001 1.添加模块 npm install --save html2canva ...

  10. VsCode中编写python环境配置

    1. VsCode中编写python环境配置 1.1. 前言 有过开发经验都知道idea一系列的软件虽然功能比较多,但比较容易卡,电脑不好还真容易上火,这里我想要入门python,还是选了款vscod ...