Best SMS to Type pku 2895
来源:互联网 发布:字符串压缩算法php 编辑:程序博客网 时间:2024/05/20 13:16
Best SMS to Type
Time Limit:1000MS Memory Limit:65536K
Total Submit:1967 Accepted:755
Description
Using SMS today is more than a pleasing hobby. As the number of messages one sends through this service grows, the need to type them fast is better felt. Sometimes, one wonders how fast a message can be typed. Changing some words to their synonyms, might help type the whole message faster, if we were able to quickly calculate the time needed for a specific message.
In the following, we assume that each message is a string of capital English letters and space character. The letters 'A' through 'Z' are assigned to keys '2' to '9', as in the following figure. To type a letter, one should press its key 1, 2, 3, or 4 times, depending on the position of the letter from left to right.
If two consecutive letters of the message are mapped to one key, one should wait for the first letter to be fixed on the screen and then use the key again to type the second one. For instance, to type the letter 'X', one should press '9' twice. If the next letter of the message is not on the same key, one can continue to type the rest of the message. Otherwise, one has to wait for some time, so that the typed 'X' is fixed, and then the next letter ('W', 'X', 'Y', or 'Z') can be typed. To type whitespace, we use the key '1'.As there is no letter mapped to the key '1', the whitespace needs no time to be fixed.
You are given the time needed to press any key, and the time one should wait for a letter to be fixed. Your program should find the minimum time needed to type a nonempty string, given the above rules.
Input
The input file contains multiple test cases. The first line of the input, contains t, the number of test cases that follow. Each of the following t blocks, describes a test case.
The first line of each block contains p and w (1 <= p,w <= 1000), which show the amount of time in milliseconds for pressing a letter and waiting for it to be fixed, respectively. The second line contains a non-empty string of length at most 1000, consisting of spaces or capital English letters. There is no leading or trailing spaces in a line.
Output
For each test case, output one line showing the time needed to type the message in milliseconds.
Sample Input
1
2 10
ABBAS SALAM
Sample Output
72
Source
Tehran 2005
#include <string>
using namespace std;
int m,n;
int mtimes,ntimes;
int a[26]=...{1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4};
int Part(char ch1)
...{
int x;
switch(ch1)
...{
case 'A':
case 'B':
case 'C': x=1;break;
case 'D':
case 'E':
case 'F': x=2;break;
case 'G':
case 'H':
case 'I': x=3;break;
case 'J':
case 'K':
case 'L': x=4;break;
case 'M':
case 'N':
case 'O': x=5;break;
case 'P':
case 'Q':
case 'R':
case 'S': x=6;break;
case 'T':
case 'U':
case 'V': x=7;break;
case 'W':
case 'X':
case 'Y':
case 'Z': x=8;break;
default :break;
}
return x;
}
int Cap(char ch1,char ch2)
...{
if(ch1==' '||ch2==' ')return 0;
int x,y;
x=Part(ch1);
y=Part(ch2);
if(x==y)return 1;
else return 0;
}
int main()
...{
int cases;
cin>>cases;
int i,len;
string str;
while(cases--)
...{
cin>>m>>n;
ntimes=0;
mtimes=0;
getline(cin,str);
getline(cin,str);
len=str.length();
for(i=0;i<len;i++)
if(str[i]==' ') ...{mtimes++;continue;}
else mtimes+=a[str[i]-'A'];
for(i=1;i<len;i++)
ntimes+=Cap(str[i-1],str[i]);
cout<<mtimes*m+ntimes*n<<endl;
}
// system("pause");
return 0;
}
- Best SMS to Type pku 2895
- poj 2895 Best SMS to Type 模拟
- POJ 2895 Best SMS to Type 笔记
- BNUOJ Best SMS To Type
- POJ 2895 Best SMS to Type 再想想
- POJ 2895 Best SMS to Type 发送短信的时间计算
- PKU 3111 K Best
- pku 3617 - Best Cow Line
- Send an SMS to yourself
- paip sms to blog.txt
- PKU 3623 Best Cow Line, Gold
- PKU 3617 Best Cow Line和PKU 3623 Best Cow Line 解题报告
- To be the best
- pku 1050 To the Max
- PKU 1050 To the Max
- pku 1922 Ride to School
- SMS
- SMS
- Linux那些事儿之我是U盘(49)跟着感觉走(一)
- 如何控制DataGrid里的内容换行与不换行?
- 什么是服务?
- 实际项目中配置SSL实例之二 weblogic8上配置ssl(共4篇)
- Miscellaneous
- Best SMS to Type pku 2895
- 学习.Net的经典网站
- 超强兔斯基。。。一学期内表情的变化--兔斯基版 转校内
- 比尔·盖茨在哈佛大学毕业典礼上的演讲
- 让你的电脑自动关机
- java 基本数据类型之间的转换
- 40种网页小技巧
- svn
- SQL Server 索引结构及其使用(一)