所有大写字母国成一圈,按照顺时针顺序分别是A,B,C……Z,输入一个大写宇母和一个数字x,请输出:
从这个大写字母开始,顺时针往后数第x个字母。(1≤2≤10000)
首先字母个数是26吧,那就是超过26的就对26取余就完事
int n = 'z' - 'A';
char c;
cin>>c;
int x;
cin>>x;
int result = (c + x) % n;
cout<<'A' + result<<endl;
代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
char n;
int x;
cin>>n>>x;
int a=n-64;
int b=a+x;
cout<<char(b+64)<<endl;
return 0;
}
运行结果: