码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #603 (Div. 2) B. PIN Codes

时间:2019-12-17 13:32:20      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:set   read   ons   step   ret   possible   select   c++   pac   

链接:

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

标签:set   read   ons   step   ret   possible   select   c++   pac   

原文地址:https://www.cnblogs.com/YDDDD/p/12053857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!