水题,直接贴代码。
//poj 2895
//sep9
#include <iostream>
using namespace std;
int map[200][2];
char a[1024];
int main()
{map[' '][0]=1,map[' '][1]=1;map['A'][0]=2,map['A'][1]=1;map['B'][0]=2,map['B'][1]=2;map['C'][0]=2,map['C'][1]=3;map['D'][0]=3,map['D'][1]=1; map['E'][0]=3,map['E'][1]=2;map['F'][0]=3,map['F'][1]=3; map['G'][0]=4,map['G'][1]=1; map['H'][0]=4,map['H'][1]=2;map['I'][0]=4,map['I'][1]=3; map['J'][0]=5,map['J'][1]=1; map['K'][0]=5,map['K'][1]=2;map['L'][0]=5,map['L'][1]=3;map['M'][0]=6,map['M'][1]=1; map['N'][0]=6,map['N'][1]=2;map['O'][0]=6,map['O'][1]=3; map['P'][0]=7,map['P'][1]=1; map['Q'][0]=7,map['Q'][1]=2;map['R'][0]=7,map['R'][1]=3;map['S'][0]=7,map['S'][1]=4;map['T'][0]=8,map['T'][1]=1; map['U'][0]=8,map['U'][1]=2;map['V'][0]=8,map['V'][1]=3; map['W'][0]=9,map['W'][1]=1; map['X'][0]=9,map['X'][1]=2;map['Y'][0]=9,map['Y'][1]=3;map['Z'][0]=9,map['Z'][1]=4;int cases,t1,t2;scanf("%d",&cases);while(cases--){scanf("%d%d",&t1,&t2); getchar();gets(a);int ans=t1*map[a[0]][1];for(int i=1;a[i]!='\0';++i){ans+=t1*map[a[i]][1];if(map[a[i]][0]==map[a[i-1]][0]&&a[i-1]!=' ')ans+=t2;}printf("%d\n",ans);}return 0;
}