An easy problem
规律:
当a >= 'a'&&a <= 'z' 时,sum = -(a - 'a') - 1;
当a >= 'A'&&a <= 'Z'时,sum = a - 'A' + 1;
代码:
#include<iostream> using namespace std; int main() { int n; char a; int b, sum; scanf("%d", &n); for (int i = 0; i < n; i++) { sum = 0; getchar(); scanf("%c %d", &a, &b); if (a >= 'a'&&a <= 'z') { sum = -(a - 'a') - 1; } if (a >= 'A'&&a <= 'Z') { sum = a - 'A' + 1; } sum = sum + b; printf("%d", sum); } system("pause"); return 0; }