HDU4167

A university’s computer system assigns user names according to the following set of rules:

The maximum length of a username is MAXLEN characters. (The value of MAXLEN will be specified in the input for each problem instance.)
The first character of the user name is the first letter of the person’s first name, converted to lower case. Ignore apostrophes and hyphens here and in Step 3.
Append as many letters of the person’s last name as possible (converted to lower case, if necessary), without exceeding a total of MAXLEN characters. Starting with the first letter of the last name, append these letters in the order in whch they appear in the last name.
If a user name assigned on basis of Rules 1 - 3 already exists in the database, break the tie as follows: append serial numbers 1 - 9, in that order, to the username from step 3, if that can be done without exceeding the limit of MAXLEN characters in the username. Otherwise, drop the last letter before appending the serial number.
If a user name assigned on basis of Rules 1 - 4 already exists in the database, break the tie as follows: append serial numbers 10 - 99, in that order, to the username from step 3, if that can be done without exceeding the limit of MAXLEN characters in the username. Otherwise, drop the last letter or the last two letters (whichever is necessary) before appending the serial number.
It is assumed that the above rules will avoid ties.

#include<iostream>
#include<string>
#include<sstream>
#include<cstdlib>
#include<set>
#include<map>
using namespace std;
int n,m;

map<string ,int>ans;

int main(){
    int po=1;
    while(cin>>n>>m && n+m!=0){
        cout<<"Case "<<po<<endl;
        po++;
        ans.clear();

        string s,a,ss;
        char b[90];
        getline(cin,s);
        for(int i=0;i<n;i++){
            getline(cin,s);
            stringstream ss(s);
            ss>>a;
            for(int i=0;i<a.length();i++){
                if(isalpha(a[i])){
                    b[0]=tolower(a[i]);
                    break;
                 }
            }
            while(ss>>a){}
            int nn=1;
            int ii=0;
            for(ii=0;ii<a.length();ii++){
                if(isalpha(a[ii])){
                    b[nn]=tolower(a[ii]);
                    nn++;
                 }
                 if(nn==m){
                    b[nn]='\0';
                    break;
                 }
            }
            if(ii==a.length())
                b[nn]='\0';
            int kk,kkk,kknum;
            if(ans[b]!=0){
                ans[b]++;
                kk=ans[b]-1;
                kkk=kk;
                kknum=0;
                while(kkk){
                    kknum++;
                    kkk/=10;
                }
                b[m-kknum]='\0';
                cout<<b;
                if(kk){
                    cout<<kk<<endl;
                }
            }
            else{
                ans[b]++;
                cout<<b<<endl;
            }

        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值