mirror of https://github.com/me50/kukemuna.git
automated commit by check50 [check50=True]
This commit is contained in:
parent
2e4ee96f07
commit
bd1536199f
37
credit.c
37
credit.c
|
|
@ -6,6 +6,7 @@ long long get_card_number(void);
|
|||
void find_issuer(long long card_number);
|
||||
int validate(long long card_number);
|
||||
int get_id(long long card_number);
|
||||
int get_length(long long card_number);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
|
@ -32,24 +33,24 @@ long long get_card_number()
|
|||
|
||||
void find_issuer(long long card_number)
|
||||
{
|
||||
int id = get_id(card_number);
|
||||
int id = get_id(card_number), count = get_length(card_number);
|
||||
|
||||
// Number beginning with 34 or 37
|
||||
if (id / 100 == 34 || id / 100 == 37)
|
||||
// Number beginning with 34 or 37 and length is 15
|
||||
if ((id / 100 == 34 || id / 100 == 37) && count == 15)
|
||||
{
|
||||
printf("AMEX\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Number beginning with 4
|
||||
if (id / 1000 == 4)
|
||||
// Number beginning with 4 and length is 13 or 16
|
||||
if ((id / 1000 == 4) && (count == 13 || count == 16))
|
||||
{
|
||||
printf("VISA\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Number beginning with 51-55 or 2221-2720
|
||||
if ((id / 100 >= 51 && id / 100 <= 55) || (id >= 2221 && id <= 2720))
|
||||
// Number beginning with 51-55 or 2221-2720 and length is 16
|
||||
if (((id / 100 >= 51 && id / 100 <= 55) || (id >= 2221 && id <= 2720)) && count == 16)
|
||||
{
|
||||
printf("MASTERCARD\n");
|
||||
return;
|
||||
|
|
@ -108,17 +109,9 @@ int validate(long long card_number)
|
|||
|
||||
int get_id(long long card_number)
|
||||
{
|
||||
int count = 0, id;
|
||||
int count = get_length(card_number), id;
|
||||
long long n, trunc = 1;
|
||||
|
||||
n = card_number;
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
n /= 10;
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count < 13 || count > 16)
|
||||
{
|
||||
return 0;
|
||||
|
|
@ -131,3 +124,15 @@ int get_id(long long card_number)
|
|||
id = card_number / trunc;
|
||||
return id;
|
||||
}
|
||||
|
||||
int get_length(long long card_number)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (card_number > 0)
|
||||
{
|
||||
card_number /= 10;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue