void f(char input[],char output[])
{
bool flag
int i=0
while (input[i]!='\0')
{
flag=true
for (int j=0j<=25j++)
{
if (input[i]==a[j])
{
flag=false
output[i]=a[(j+1)%26]
break
}
else if (input[i]==A[j])
{
flag=false
output[i]=A[(j+1)%26]
break
}
}
if (flag==true)
{
output[i]=input[i]
}
i++
} // 将最后一个 '\0' 赋值给结果,表示字符串
结束
output[i]=input[i]
}#include<stdio.h>
#include<string.h>
void main ()
{
char str[100]
char str1[100]
printf("输入字符串:")
scanf("%s",&str)
int len
len=strlen(str)
for(int i=0i<leni++)
{
str1[i]=(str[i]-97+3)%26+97
}
str1[len]='\0'
printf ("密文为:%s\n",str1)
}#include <iostream>
#include <string>
using namespace std
int main()
{
string code//储存初始字符串
string d_code//加密后的字符串
int i
int n //移位的个数
cout<<"Enter the string "<<endl
cin>>code
cout<<"how many step do you want to move ?"<<endl
cin>>n
for(i=0i<code.size()++i)
{
if(int(code[i])>97)
{
if(int(code[i])+n>122)
d_code[i]=int(code[i])+n-26
else
d_code[i]=int(code[i])+n
}
else if(int(code[i])+n>90)
d_code[i]=char(int(code[i])+n-26)
else
d_code[i]=char(int(code[i]+n))
}
for(i=0i<code.size()++i)
{
cout<<d_code[i]
}
cout<<endl
cout<<"Code = "<<code<<endl
return 0
}
评论列表(0条)