输入的字符串(字符串仅包含小写字母‘a’到‘z’),按照如下规则,循环转换后输出:a->b,b->c,…,y->z,

2025-06-23 06:04:50
推荐回答(1个)
回答1:

数组的输出你写错了!要用for循环一个个输出
你要限制不能输入超过5个字符就要加一个判断语句。
我把你写的修改了一下。
#include
#include"string.h"
using namespace std;
void convert(char *input,char* output)
{
for(int i=0;i<5;i++)
{
output[i]=(input[i]-'a'+1)%26+'a';
}

}

void main()
{
char input[5];
char output[5];
cout<<"输入字母:";
cin>>input;
int length=strlen(input);
while(length>5) //判断输入个数是否超过5个
{
cout<<"输入错误,请重新输入"< cin>>input;
length=strlen(input);
}

convert(input,output);
cout<<"输出是:";
for(int i=0;i<5;i++)
{
cout< }
cout<}