B3956 [GESP202403 三级] 字母求和 题解

basibatuo / 2024-08-04 / 原文

当时在考试,3分钟A了,结果第二题T了。

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
#define fo(i,n,m) for(int i=n;i<=m;i++)
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, cnt = 0;
	string a;
	cin >> n >> a;	// 输入字符串
	fo(i, 0, a.length() - 1)	// 遍历字符串
	if (a[i] >= 'a' && a[i] <= 'z')	// 判断是不是小写字母
		cnt += (a[i] - 'a' + 1); // 算出来他是26个字母的第几个
	else	// 否则就只有大写字符了,题目里写了只有大写和小写字母
		cnt += (int) - a[i]; // 按照题意,删掉ASCII码值。
	cout << cnt;
	return 0;
}