杭电ACM2055

Problem 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 should output the result of y+f(x).
 

Input
On the first line, contains a number T.then T lines follow, each line is a case.each case contains a letter and a number.
 

Output
for each case, you should the result of y+f(x) on a line.
 

Sample Input
 
  
6R 1P 2G 3r 1p 2g 3
 

Sample Output
 
  
191810-17-14-4

首先这道题。。坑人

才开始理解为该题上面的规律,不知道咋解,后来看了输出的答案才知道是自己找规律。。英语不好。

#include<iostream>
using namespace std;

int main(){
	int n,y;
	char fx;
	cin>>n;
	while(n--){
		cin>>fx>>y;
		if('a'<=fx&&fx<='z')
			cout<<y-(fx-'a'+1)<<endl;
		else
			cout<<(fx-'A'+1+y)<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40728285/article/details/79996798