这是一个游戏党出的题,原先你有这么多技能,右边是熟练度或者记忆度之类的东西,然后你学习了一些技能的同时以一个比率对已有技能的记忆能力降低成这个比率的数值(遗忘),以前没学过的技能就是0熟练度,学过的技能如果低于100就被忘掉了,问这次学习之后还剩多少技能以及他们的熟练度。
这里我用了map的数据结构,将string和int绑在一起用map是很棒的哦~
先make_pair(str,int*rate) 然后把整数部分不小于100的pair给push进map中,判断新学技能有没有原先不会的,有的话push进去(int部分是0哦)。
最后把map里的东西都打印出来即可。
Code
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
// http://codeforces.com/contest/105
// Transmigration
map<string,int> mp;
int main()
{
int n,m;
double rate;
cin>>n>>m>>rate;
int rat=(int)(rate*100);
for(int i=0;i<n;i++)
{
string name;
double p;
cin>>name>>p;
int pp=p*rat/100;
if(pp>=100) mp.insert(make_pair(name,pp));
}
for(int i=0;i<m;i++)
{
string name;
cin>>name;
if(mp[name]==0)mp.insert(make_pair(name,0));
}
cout<<mp.size()<<endl;
for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;
}
return 0;
}