A letter and a number

Source: Internet
Author: User
Parameter between a letter and a number description
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 shoshould output the result of Y + f (x ).
Input
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 ).
Output
For each case, You shoshould the result of Y + f (x) on a line
Sample Input
6R 1P 2G 3r 1p 2g 3
Sample output
191810-17-14-4
Solution:
N groups of data are involved in this question, and each group of data starts with a character. scanf reads a line feed first, so you should use getchar to eat the carriage return before reading each line of data, no, only half of the data can be read.
Program code:
#include<stdio.h>int main(){int n,y,i;char x;scanf("%d",&n);while(n--){getchar();scanf("%c%d",&x,&y);if(x>='a'&&x<='z')printf("%d\n",'a'-x-1+y);else if(x>='A'&&x<='Z')printf("%d\n",x-'A'+1+y);}return 0;}

A letter and a number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.