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).
Give you a letter x and a number y , you should output the result of y+f(x).
6 R 1 P 2 G 3 r 1 p 2 g 3
19 18 10 -17 -14-4
#include<iostream> using namespace std; int main() { char a[28]={" abcdefghijklmnopqrstuvwxyz"},b[28]={" ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
//C语言总是在编译时为字符串常量自动在其后增加一个空字符 int m,i,x,j,k; char n; cin>>k; for(j=0;j<k;j++) { cin>>n>>m; for(i=1;i<27;i++) { if(n==a[i]) { x=i*(-1); } } for(i=1;i<27;i++) { if(n==b[i]) { x=i; } } cout<<m+x<<endl; } return 0; }