1263B - PIN Codes - CodeForces Solution


greedy implementation *1400

Please click on ads to support us..

C++ Code:

// Author: MAMUN MIAH
// Date:23 February 2023
// Link:

#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define ll long long
#define pb push_back
void solve()
{
    int n;
    cin >> n;
    string pin;
    vector<int> check(10, 0);
    vector<string> keep;
    int ans = 0, dup = n;
    while (n--)
    {
        cin >> pin;
        check[pin[0] - '0'] = 1;
        keep.pb(pin);
    }
    for(int i = 0; i < dup; i++)
    {
        for(int j = i + 1; j < dup; j++)
        {
            if(keep[i] == keep[j])
            {
                ans++;
                for(int k = 0; k <= 9; k++)
                {
                    if(!check[k])
                    {
                        keep[i][0] = '0' + k;
                        check[k] = 1;
                        break;
                    }
                }
                break;
            }
        }
    }
   
    cout << ans << endl;
    for (auto x : keep)
    {
        cout << x << endl;
    }
}
int main()
{
    ios_base ::sync_with_stdio(false);
    cin.tie(nullptr);
    int test;
    test = 1;
    if (true)
    {
        cin >> test;
    }

    while (test--)
    {
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

215B - Olympic Medal
1445A - Array Rearrangment
1351A - A+B (Trial Problem)
935B - Fafa and the Gates
1291A - Even But Not Even
1269A - Equation
441A - Valera and Antique Items
1702C - Train and Queries
816B - Karen and Coffee
838D - Airplane Arrangements
148B - Escape
847G - University Classes
1110A - Parity
1215B - The Number of Products
604C - Alternative Thinking
1204C - Anna Svyatoslav and Maps
322A - Ciel and Dancing
1689B - Mystic Permutation
1711B - Party
1702D - Not a Cheap String
1714F - Build a Tree and That Is It
1703F - Yet Another Problem About Pairs Satisfying an Inequality
610A - Pasha and Stick
1200A - Hotelier
1091A - New Year and the Christmas Ornament
1352B - Same Parity Summands
1102A - Integer Sequence Dividing
630B - Moore's Law
1004A - Sonya and Hotels
1680B - Robots