题意:
一个角色有n种技能,并且有相应的经验水平exp,在角色死亡后,出现新的角色能继承以前角色的技能经验,但只能有k的继承效能,并且是取整的值,小于100就不能继承下来,而新的角色可以学习新的技能,但初始经验为零,问在一次轮回后该角色所拥有的技能和经验值,并按字典序输出。
思路:直接算出技能继承后的值大于一百的存下来,并用map标记,在新的角色中技能判断是否有标记过,没有就存下来,再排序输出就行了,此题有点卡精度,否则很容易WA。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define eps 1e-6
using namespace std ;
struct node{
char name[22];
int exp;
}ans[55];
bool cmp(node a,node b){
return strcmp(a.name,b.name)<0;
}
int main()
{
int n,m,tmp,exp;
double k;
char s[22];
int e=0;
map<string,int>mt;
scanf("%d %d %lf",&n,&m,&k);
for(int i=0;i<n;i++){
scanf("%s %d",s,&exp);
tmp=int(exp*k+eps);
if(tmp>=100){
strcpy(ans[e].name,s);
ans[e++].exp=tmp;
mt[s]=1;
}
}
for(int i=0;i<m;i++){
scanf("%s",s);
if(mt[s]==0) strcpy(ans[e].name,s),ans[e++].exp=0;
}
sort(ans,ans+e,cmp);
printf("%d\n",e);
for(int i=0;i<e;i++) printf("%s %d\n",ans[i].name,ans[i].exp);
return 0 ;
}