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

当时在考试,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;
}

本文作者:basibatuo

本文链接:https://www.cnblogs.com/basibatuo/p/18314311

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   非气盈门  阅读(215)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起