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

URAL 1567. SMS-spam (小学数学题)

时间:2015-03-07 11:36:09      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

1567. SMS-spam

Time limit: 1.0 second
Memory limit: 64 MB
Petr, a student, decided to start his own business. He offers SMS advertising services to the business owners renting offices in the newly built “Prisma” tower. If an office owner wants to use the service, he devises a slogan and Petr texts it from his personal phone to thousands of Ekaterinburg citizens (he already bought the pirated list of mobile phone numbers). The cost of each slogan sent is a sum of costs of each character typed. Cost of an individual character is determined according to a very simple scheme: each tap at the phone‘s keyboard costs 1 rouble.
Petr‘s phone doesn‘t support sophisticated text input technologies, such as T9, and only the english alphabet can be used.
1
abc
2
def
3
ghi
4
jkl
5
mno
6
pqr
7
stu
8
vwx
9
yz
  0
.,!
#
_
The “_” 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.
Petr has to apply this simple algorithm to calculate the cost of every slogan he sends. However, Petr is a very busy man (and, as a matter of fact, doesn‘t bother to learn arithmetics, because he‘s a Philosophy student). You just have to help Petr, you are his best friend after all.

Input

The single line of input contains the slogan. Slogan consists of words, spaces, commas, full stops and exclamation marks. All the words consist of lowercase english letters. Slogan can‘t be longer than 1000 characters.

Output

Output a single number representing the cost of the given slogan, according to Petr‘s pricing.

Sample

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



URAL 1567. SMS-spam (小学数学题)

标签:

原文地址:http://blog.csdn.net/u013446688/article/details/44114627

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