BNUOJ Best SMS To Type
来源:互联网 发布:四川省南充市行知小学 编辑:程序博客网 时间:2024/05/16 18:31
Best SMS to Type
64-bit integer IO format: %lld Java class name:Main
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 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
Sample Input
12 10ABBAS SALAM
Sample Output
72
很水的模拟题,注意: 可能有连续输入的空格。。。
#include<stdio.h>
#include<string.h>
char str[1005];
long long sum;
int a[1005];
int s[8][4]={{'A','B','C','0'},{'D','E','F','0'},{'G','H','I','0'},{'J','K','L','0'},
{'M','N','O','0'},{'P','Q','R','S'},{'T','U','V','0'},{'W','X','Y','Z'}};
int main()
{
int t,i,j,n,p,w,k;
while(scanf("%d",&n)!=EOF)
{
while(n--){
sum=0;
scanf("%d%d",&p,&w); // p: 按一次键需要的时间,w: 同一个键上的字符间隔时间
getchar();
gets(str);
memset(a,0,sizeof(a));
t=0;
for(i=0;i<strlen(str);i++){
if(str[i]==' ') { a[t++]=-1; sum+=p; }
else {
for(j=0;j<8;j++)
for(k=0;k<4;k++)
if(str[i]==s[j][k]){
sum+=((k+1)*p);
a[t++]=j;
}
}
}
for(i=0;i<t-1;i++)
if(a[i]==a[i+1] && a[i]!=-1) sum+=w;
printf("%lld\n",sum);
}
}
system("pause");
return 0;
}
- BNUOJ Best SMS To Type
- Best SMS to Type pku 2895
- poj 2895 Best SMS to Type 模拟
- POJ 2895 Best SMS to Type 笔记
- POJ 2895 Best SMS to Type 再想想
- POJ 2895 Best SMS to Type 发送短信的时间计算
- Send an SMS to yourself
- paip sms to blog.txt
- To be the best
- SMS
- SMS
- SMS
- SMS
- sms
- SMS
- SMS
- sms
- SMS
- for(二)
- CComPtr和CComQIPtr
- CComPtr用法
- Windows下ndk搭建图文教程
- JavaScript第五章知识点总结——常用DHTML对象 Window对象 对话框 定时器
- BNUOJ Best SMS To Type
- 超炫天猫商城多格子带遮罩效果焦点图
- ios 应用程序远程测试
- Android 真机调试
- badstore安全测试实验
- 减少Linux状态Time_wait的TCP链接
- 泛型实现二叉树
- poj1721 CARDS----置换
- CSS line-height 和 vertical-align 精解