c++字母相连输出

来源:百度知道 编辑:UC知道 时间:2024/06/09 01:19:58
设计一个程序,从键盘输入一个大写英文字母,在主函数中实现。在自定义函数中要求字母的顺序打印出3个相邻的字母,指定的字母在中间。如指定的字母为Z,则打印YZA;若为A,则打印ZAB. 用分支、函数做~ 谢谢。
用c++实现,请各位帮帮忙 谢了。

大概这样写:
#include "iostream"
using namespace std;

char map[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

void p(char c) {
int index = c - 'A';
if (index == 0) {
cout<<map[25];
} else {
cout<<map[index-1];
}
cout<<map[index];
if (index == 25) {
cout<<map[0];
} else {
cout<<map[index+1];
}

}

void main() {
char c;
cin>>c;
p(c);
}