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

33 篇文章 0 订阅
23 篇文章 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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值