数据
ipt
5 458
w5w 67
uU 54
VEk 65
kuC 42
Cj5 4
CLqq fw WnRG !
Cj5? ,Nd !
?gb3C ! !w5w Xbp ? Cj5 ? ?I8s
opt
75
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
int n,p,a,ans;
map <string,int> cg;
string s;
char c;
signed main()
{
IO cin>>n>>p;
for(int i=1;i<=n;i++)cin>>s>>a,cg[s]=a;
s.clear();
while( (c=getchar()) != EOF)
{
if(c==' ' || c==',' || c== '!' || c=='.' || c=='?')
{
ans += cg[s];
ans %= p;
s.clear();
}
else s+=c;
}
cout<<ans;
return 0;
}