作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个非常有趣的案例。我已经编写了已编译的源代码,并且可以正常工作,但是当我将代码添加到类(class)中以供审核时,出现了下一个问题:
:) credit.c exists.
:) credit.c compiles.
:( identifies 378282246310005 as AMEX expected "AMEX\n", not "\nAMEX\n"
:( identifies 371449635398431 as AMEX expected "AMEX\n", not "\nAMEX\n"
:( identifies 5555555555554444 as MASTERCARD
expected "MASTERCARD\n", not "\nMASTERCARD\n"
:) identifies 5105105105105100 as MASTERCARD
:) identifies 4111111111111111 as VISA
:( identifies 4012888888881881 as VISA
expected "VISA\n", not "\nVISA\n"
:( identifies 1234567890 as INVALID
expected "INVALID\n", not "\nINVALID\n"
:) identifies 369421438430814 as INVALID
:( identifies 4062901840 as INVALID
expected exit code 0, not 1
:) identifies 5673598276138003 as INVALID
:( identifies 4111111111111113 as INVALID
expected exit code 0, not 1
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""
下一部分是我的代码:
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main (void)
{
long long card_num;
// getting card number
do
{
card_num = get_long("Number: \n");
}
while (card_num < 1 || card_num > 9999999999999999);
for (int i = 0; i < card_num.length(); i++)
{
if (card_num[i] == '-')
printf('foo\n');
card_num[i] == '';
else (card_num[i] == ' ')
printf ('foo\n');
card_num[i] == '';
}
long long temp_num = card_num;
int count = 0;
while (temp_num > 0)
{
temp_num = temp_num / 10;
count++;
}
// umber volume cheking
if (count != 13 && count != 15 && count != 16)
{
printf("INVALID\n");
return 1;
}
// luna's algorithm checking
int sum = 0;
temp_num = card_num;
for (int i = 1; i <= count; i++)
{
int digit = temp_num % 10;
if (i % 2 == 0)
{
digit *= 2;
if (digit > 9)
{
digit -= 9;
}
}
sum += digit;
temp_num /= 10;
}
if (sum % 10 != 0)
{
printf("INVALID\n");
return 1;
}
// bank info cheking
temp_num = card_num;
while (temp_num > 100)
{
temp_num = temp_num / 10;
}
int company_id = temp_num;
if (company_id > 50 && company_id < 56 && count == 16)
{
printf("MASTERCARD\n");
}
else if ((company_id == 34 || company_id == 37) && (count == 15))
{
printf("AMEX\n");
}
else if ((company_id / 10 == 4) && (count == 13 || count == 16))
{
printf("VISA\n");
}
else
{
printf("INVALID\n");
}
return 0;
}
最佳答案
好消息! CS50有自己的SE社区,你可以找到here .
密切注意错误告诉您的内容。某处输出了一个额外的回车符 (\n
),如下所示: :( 将 378282246310005 标识为 AMEX 预期的“AMEX\n”,而不是“\nAMEX\n”
。请注意 check50 期望的内容 ("AMEX\n"
) 和程序输出的内容 ("\nAMEX\n"
) 之间的差异。纠正后它将消除 5 个错误。好的开始。
检查代码以查看其返回退出代码 1 的位置。规范不要求这样做。遵守规范。有时并不是越多越好:)。纠正后,将消除最后两个错误。
也许这些看起来像是小细节,不应该影响评分。但如果老板或客户希望严格遵守规范,这些“小细节”就可以转化为真正的金钱。
关于CS50学分任务回顾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58839140/
我正在 Facebook 上开发应用程序,我需要能够将我的应用程序集成到其他站点(通过 Facebook JavaScript API 连接到 Facebook)。 在 Facebook 上,我可以使
我正在制作一个学生数据库,其中包含类(class) ID、类(class)名称、每门类(class)的学分、通过/失败声明和成绩。我的目标是让按钮显示总和(成绩)/总和(学分) 这是我编写的代码,它给
我是一名优秀的程序员,十分优秀!