#include <stdio.h>
int main(int argc, string argv[])
{
Get input from the user;
Store it in a long long int;
// iterate through the number
for each odd number in the input multiply by 2
if the number is bigger than 9 then
do module of it and add it to the first number;
store it into metasum;
for each even number in the input
add it to the others;
store the result into metasum2;
// is it a valid card?
if (metasum + metasum2)%10 == 0
{
card is valid;
// check which kind of cc is
if the input begins with a 3 then it's an AMEX;
else if the input begins with 4 it is a VISA;
else if the input begins with 5 it is a MASTERCARD;
}
else
{
card is not valid;
}
}
它实际上是一种伪代码。我正在参加 CS50x,我想知道我的伪代码实现是否足够好。
不过我还有另一个问题,当我尝试在 CI 中实现代码时,不知道如何遍历 long long int,所以我无法实现 Luhn 算法。
如何在不使用字符串然后将每个 char 转换为 int 的情况下做到这一点?
感谢您的答复