URAL 1567. SMS-spam (小学数学题)
来源:互联网 发布:java在数据库中写的表 编辑:程序博客网 时间:2024/05/01 21:30
1567. SMS-spam
Time limit: 1.0 second
Memory limit: 64 MB
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
abc2
def3
ghi4
jkl5
mno6
pqr7
stu8
vwx9
yz 0
.,!#
_
abc2
def3
ghi4
jkl5
mno6
pqr7
stu8
vwx9
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
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
- URAL 1567. SMS-spam (小学数学题)
- URAL 1068. Sum (小学数学题)
- URAL 2001 Mathematicians and Berries (小学数学题)
- 小学数学题
- 小学数学题一道
- 一道小学的数学题
- 小学数学题 洛谷p2921
- URAL 1427. SMS
- 【Ural】1066 数学题 Garland
- URAL 1515 Cashmaster 数学题
- 小学数学题,看看现在还会做吗?
- 一道小学数学题[状元蹄]
- 传说中的越南小学数学题
- 坑爹的小学数学题
- hdoj1049 Climbing Worm(小学数学题)
- URAL 1427. SMS (线性dp)
- 一道小学五年级的数学题
- 一个小学数学题引发的血案
- IaaS, PaaS和SaaS公司都做些什么
- JAVA 子类方法签名相同 返回类型不同
- URAL 1296. Hyperjump(最大子序列和)
- 现货交易止损是控制风险的最好方法
- 软件测试方法汇总(转载)
- URAL 1567. SMS-spam (小学数学题)
- 两个数最大公约数,证明与实现
- PAT A1011. World Cup Betting
- Deweb : 开始一段伟大的历程!
- UC的U3、百度的T5和腾讯的X5内核webview的调试工具---DebugGap
- C++内存泄露和检测
- SQL SELECT的用法
- 简单通用数据访问映射层
- 借助C++进行windows API开发 by Kenny Kerr