题目六:2055.An easy problem
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.
#include <iostream>
#include <vector>
using namespace std;
int main() {
int m, n;
char c;
vector<int> num(26);
for (int i = 0; i < 26; i++) {
num[i] = i + 1;
}
while (cin >> m) {
while (m--) {
cin >> c >> n;
if (c >= 'a' && c <= 'z') {
n = n - num[c - 'a'];
} else if (c >= 'A' && c <= 'Z') {
n = n + num[c - 'A'];
}
cout << n << endl;
}
}
return 0;
}
题目七:2010.水仙花数
Problem Description