4

1-3 英文字母

 1 year ago
source link: https://hbuacm.github.io/2023/01/07/2023%E5%AF%92%E5%81%87%E8%AE%AD%E7%BB%831-3%20%E8%8B%B1%E6%96%87%E5%AD%97%E6%AF%8D/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

HBUACM

1-3 英文字母
发表于 2023-01-07| 更新于 2023-01-07|2023程序设计训练营题解
阅读量:2

在计算机内部,英文字母依ASCII码分别由连续的整数来表示。比如,大写的英文字母A的ASCII码值为65,B的码值为66,然后依次递增,Z的码值为90。

请编程计算:

从键盘读取大写字母Q(代号,其值由具体输入确定),请问Q所代表的大写字母是字母表中的第几个字母(从1开始计数,即A为第1个字母)?
从键盘读取整数N,求字母表中的第N个字母(从1开始计数)是什么?

输入格式:

说明:是一个字符的大写字母;N的取值范围为1~26。

输出格式:

请参考输出样例。

输入样例:

B
3

输出样例:

2
C
C++
#include<bits/stdc++.h>
using namespace std;

int main(){
char q;
int n;
cin >> q;
cin >> n;
cout << (int)q - 64 << endl;
cout << (char)(n + 64);
return 0;
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK