Ceasar Cypher不会计算空间
Ceasar Cypher would not count spaces
我正在编写一个具有4个不同函数的程序,其中一个人询问用户是否要编码/解码,另一个函数在动态内存中包含字符串的输入,实际解密功能和输出功能。我做了所有事情,但是我唯一的问题是考虑到输入的单词中是否有空间。
在我的解密功能中,我写道,如果给定的单词的索引有一个空间,那么它将继续并跳过该索引。编辑:我现在包括输入函数和读取单词并加密的输出函数。
string *input(){
string *temp = new string;
cout<<"What is the word: ";
getline(cin, *temp);
cin >> *temp;
return temp;
}
string output(string *in){
string cypher;
cypher = decryption(*in);
cout<<"Result: "<<cypher<<endl;
return cypher;
}
string decryption(string in){
int inputSize = in.size();
int index = 0;
while(index != inputSize){
if(in[index] == ' '){//possibly something wrong with this if statement
index++;
}else if(in[index] >= 97 && in[index] <= 109){
in[index]= in[index]+13;
}else if(in[index] >=110 && in[index] <=122){
in[index] = in[index]-13;
}else if(in[index] >=65 && in[index] <=77){
in[index] = in[index]+13;
}else if(in[index] >=78 && in[index] <=90){
in[index] = in[index]-13;
}
index++;
}
return in;
}
预期结果:输入" E"或" D"以编码或解码。退出的其他钥匙:E什么是:字母结果:nycunorg
输入'e'或'd'进行编码或解码。退出的其他钥匙:E什么是:taf vf结果:GNS是
到目前为止,我的结果:输入" E"或" D"以编码或解码。退出的其他钥匙:E什么是:taf vf结果:GNS
当您遇到空间时,您有效地增加了index
- 一次在该if
子句中,然后在循环的末端再次递增。这具有跳过(未编码(的净效果。
只需删除整个if(in[index] == ' ')
子句即可。其余代码已经使任何不属于四个特殊检查的范围的角色保持不变 - 包括空间。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 递归函数计算序列中的平方和(并输出过程)
- 命名空间中具有.h和.cpp文件的类
- 从父命名空间重载类型
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- (C++)分析树以计算返回错误值的简单算术表达式
- 我的字符计数代码计算错误.为什么
- 当 A 在 for 循环中调用函数 B 时,如何计算函数 A 的空间复杂度?
- Ceasar Cypher不会计算空间
- 如何使用 strlen 计算空间并在 sprintf 中加载
- C++ 计算空空间
- 如何计算程序的空间复杂度
- PHP / C++包裹包装的空间计算
- 从vtk渲染计算摄影机空间坐标
- 为什么计算的可用和总驱动器空间上限为2G?
- 用于计算色差(delta E)和颜色空间转换的C/ c++库
- 如何计算下列结构体所占用的内存空间
- 计算RLE压缩字符串所需的空间
- 计算无序映射占用的内存空间