NYOJ-a letter and a number

a letter and a number

时间限制:3000 ms  |  内存限制:65535 KB

难度:1

描述
we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;

Give you a letter x and a number y , you should output the result of y+f(x).

输入
On the first line, contains a number T(0<T<=10000).then T lines follow, each line is a case.each case contains a letter x and a number y(0<=y<1000).
输出
for each case, you should the result of y+f(x) on a line
样例输入
6
R 1
P 2
G 3
r 1
p 2
g 3
样例输出
19
18
10
-17
-14
-4
代码:

[objc] view plaincopyprint?

  1. #include<stdio.h>
  2. int main()
  3. {
  4. int t,y;
  5. char ch;
  6. scanf("%d",&t);
  7. while(t--)
  8. {
  9. getchar();  //注意字符输入时可能出现的问题,否则ch可能会接收‘\n‘;
  10. scanf("%c%d",&ch,&y);
  11. if(ch>=‘a‘&&ch<=‘z‘)
  12. printf("%d\n",y-(ch-‘a‘+1));
  13. else
  14. printf("%d\n",y+(ch-‘A‘+1));
  15. }
  16. return 0;
  17. }

时间: 2024-08-11 09:53:54

NYOJ-a letter and a number的相关文章

a letter and a number

 a letter and a number描述 we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26; Give you a letter x and a number y , you should output the result of y+f(x). 输入 On the first line, contains a number T(0<T<=10000).then T lines

ACM-a letter and a number

描述 we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26; Give you a letter x and a number y , you should output the result of y+f(x). 输入 On the first line, contains a number T(0<T<=10000).then T lines follow, each line is a

Java经典算法(一)

Java中经典的一些算法(一) [程序01]题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 分析:第一个月兔子对数为1,第二个月兔子对数为1,第三个月兔子对数为2,第四个月兔子对数为3,第五个月兔子对数为5,.... 该"兔子数列"(也即是斐波那契数列),从第二项开始,每一项都等于前两项之和,1,1,2,3,5,8,13,21,34,....   需要注意的是第一个1代表的是第1项,第

bzoj:1687;poj 2434:[Usaco2005 Open]Navigating the City 城市交通

Description A dip in the milk market has forced the cows to move to the city. The only employment available is in the venerable field of taxi-driving. Help the cows learn their way around the city. Given a city map with E (1 <= E <= 40) east/west st

46 Simple Python Exercises 16-22题

会贴出原题和答案,答案不是最优的,也反映了我的学习过程,如果有时间会更新优化的代码. Write a function filter_long_words() that takes a list of words and an integer n and returns the list of words that are longer than n. #Write a function filter_long_words() that takes a list of words # and a

验证密码必须是字母加数字的组合

function validPsw(password) {       var num = 0;       var number = 0 ;       var letter = 0 ;       var bigLetter = 0 ;       var chars = 0 ;              if (password.search(/[0-9]/) != -1) {           num += 1;           number =1;       }       i

Regex Password Validation

You need to write regex that will validate a password to make sure it meets the follwing criteria: At least six characters long contains a lowercase letter contains an uppercase letter contains a number function validate(password) { return /^(?=.*\d)

[华为机试练习题]4.简单密码破解

题目 描述: 密码是我们生活中非常重要的东东,我们的那么一点不能说的秘密就全靠它了.哇哈哈. 接下来渊子要在密码之上再加一套密码,虽然简单但也安全. 假设渊子原来一个BBS上的密码为zvbo9441987,为了方便记忆,他通过一种算法把这个密码变换成YUANzhi1987,这个密码是他的名字和出生年份,怎么忘都忘不了,而且可以明目张胆地放在显眼的地方而不被别人知道真正的密码. 他是这么变换的,大家都知道手机上的字母: 1–1, abc–2, def–3, ghi–4, jkl–5, mno–6,

c++引擎开发

MyMap.erase(Itor++); //在windows下也可以Itor = MyMap.erase(Itor),但是在linux下不行. 一个是把指针定为const .就是不能修改指针.也就是char * const p一个是把指针指向的内容定为const .就是不能修改指针指向的内容 也就是const char *p 简单来记就是你看const距离char近还是*近.距离char近就是将char类型的内容定为cosnt距离*近就是把指针定为conststruct OBJECT { in