您的位置:首页 > 大数据 > 人工智能

字符->UVALive 4773 YY and YY Again

2013-10-12 18:24 513 查看
YY and YY AgainTime Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluSubmit Status Practice UVALive4773DescriptionIf we define each of the upper case letters a number, that is, 1 for A, 2 for B, 3 for C, ... 25 for Y, 26 for Z, we can calculate a mark for any word or sentence.We believe that 100 points is the full mark, so for those word with a mark larger than 100, we should just ignore that, with a label ``INVALID". Then let's see interesting results:What is the most important for your success?HARD WORK? H+A+R+D+W+O+R+K=8+1+18+4+23+15+18+11=98KNOWLEDGE? K+N+O+W+L+E+D+G+E=11+14+15+23+12+5+4+7+5=96MONEY?(72)LUCK?(47)ATTITUDE! A+T+T+I+T+U+D+E=1+20+20+9+20+21+4+5=100So just be with good attitude and you will be on your way to success.InputFor each case of the input, it contains a single line. For each line, some characters will appear with maybe some of them being upper case letters. All characters are printable. Each line will have at most 127characters.OutputFor each case, you should only pay attention to upper case letters and calculate the total points. If it is over 100, ``INVALID" should be returned. Or you should print the exact point of that.Sample Input
DELICIOUS FOOD
YY, and YY again!
did i lose anything?
Sample Output
INVALID
100
0
#include <stdio.h>#include <string.h>char str1[200], str2[200];int main(){int ans;while(scanf("%s", str1) != EOF){gets(str2);int len1 = strlen(str1), len2 = strlen(str2);ans = 0;for(int i = 0; i < len1; i++){if(str1[i] >= 'A' && str1[i] <= 'Z'){ans += str1[i] - 'A' + 1;}}for(int i = 0; i < len2; i++){if(str2[i] >= 'A' && str2[i] <= 'Z'){ans += str2[i] - 'A' + 1;}}if(ans > 100){printf("INVALID\n");}else{printf("%d\n", ans);}}return 0;}
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: