作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现凯撒密码,但没有得到预期的输出。代码有什么问题?
Key: 3
Input: Hello
Output I'm getting: KNUUX
Expected Output: KHOOR
代码:
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, string argv[])
{
if(argc!=2)
{
return 1;
}
int k, i;
k = atoi(argv[1]);
printf("Enter the String to Encrypt: ");
string s=GetString();
for(i=0; i<strlen(s); i++)
{
if('A'>=s[i]<='Z')
{
s[i]=((s[i] - 'A' + k)%26) +'A';
}
else if('a'>=s[i]<='z')
{
s[i]=((s[i] - 'a' + k)%26) +'a';
}
}
printf("The Encrypted Text is %s\n",s);
}
最佳答案
if('A'>=s[i]<='Z')
肯定没有按照您的预期行事。
您可能想要:
if ( (s[i] >= 'A') && (s[i] <= 'Z') )
关于c - 凯撒密码的实现有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21744557/
我刚刚开始学习 C 语言类(class),并且遇到了命令行参数的问题。分配是这样的(还有更多,但这是开头有关命令行参数的部分): - 你的程序必须接受一个命令行参数,一个非负整数。 - 如果您的程序在
我需要检查命令行参数中是否有非数字字符。例如: ./problem 20x 应该打印出“不是数字”,因为它包含一个 x。我的代码似乎没有循环遍历命令行参数中的所有字符。 我基本上尝试了不同类型的循环,
这里我有从标准输入将字符流输入到数组中的代码。然后将该数组转换为二维数组。然后,它将该数组从行列顺序更改为列行顺序。然后它打印出创建凯撒移位加密的新数组。我遇到的问题是我的数组开始使用第二个用户输入的
我有点被这个问题困住了。当我运行程序时,由于某种原因,循环经过 z 的所有字母都不会打印。问题来自这个链接:http://docs.cs50.net/2016/x/ap/problems/caesar
我是一名优秀的程序员,十分优秀!