|
1 abc |
2 def |
3 ghi |
|
4 jkl |
5 mno |
6 pqr |
|
7 stu |
8 vwx |
9 yz |
|
0 .,! |
# _ |
_” character in the table denotes whitespace. If you want to, for example, type “a”,
you need to press the “1” button once. To type “k”, you press “4”
twice. To type “!”, press “0” three times.| input | output |
|---|---|
pokupaite gvozdi tolko v kompanii gvozdederov i tovarischi! |
114 |
题意:按照表格计算所给句子需要敲击多少下键盘。
解析:对字母直接求余计算即可,特殊处理下非字母的字符。
AC代码:
#include <cstdio>
#include <cstring>
char s[1002];
int main(){
#ifdef sxk
freopen("in.txt", "r", stdin);
#endif //sxk
int ans;
while(gets(s)){
ans = 0;
int len = strlen(s);
for(int i=0; i<len; i++)
if(s[i] >= 'a' && s[i] <= 'z') ans += (s[i] - 'a') % 3 + 1; //字母
else if(s[i] == '.' || s[i] == ' ') ans += 1; //特判非字母
else if(s[i] == ',') ans += 2;
else ans += 3;
printf("%d\n", ans);
}
return 0;
}
原文:http://blog.csdn.net/u013446688/article/details/44114627