• Codeforces 1263B PIN Codes


    思路:

    水题一道,刚开始把题目看错了卡了好久orz;
    由于nn小于等于10,我们只需要对第一个数字进行修改就能保证各不相同了~

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    map<string,int> mp;
    void change(string& s){
    	char c='0';
    	for(int i=0;i<=9;i++){
    		s[0]=c+i;
    		if(mp[s]==0){
    			mp[s]++;break;
    		}
    	}
    }
    int main(){
    	ios::sync_with_stdio(false);
    	cin.tie(NULL);
    	int t; cin>>t;
    	while(t--){
    		int n; cin>>n;
    		mp.clear();
    		vector<string> v(n);
    		int ans=0;
    		for(int i=0;i<n;i++){
    			cin>>v[i];
    			mp[v[i]]++;
    		}
    		for(string& e:v){
    			if(mp[e]>1) mp[e]--,change(e),ans++;
    		}
    		cout<<ans<<'
    ';
    		for(auto e:v) cout<<e<<'
    ';
    	}
    	return 0;
    }
    
  • 相关阅读:
    14 循环结构
    12.Maps
    11 Lists
    10 正则表达式
    8 Operator overloading
    9 Strings
    7 数据类型
    6 GPath
    4 练习: 使用eclipse开发
    5 类、对象、方法
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308799.html
Copyright © 2020-2023  润新知