码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2895 Best SMS to Type 模拟

时间:2014-12-28 00:32:46      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:poj

水题,直接贴代码。

//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;
} 


poj 2895 Best SMS to Type 模拟

标签:poj

原文地址:http://blog.csdn.net/sepnine/article/details/42202849

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!