Last active
August 29, 2015 14:07
-
-
Save RexYuan/f9a7576ef0014cada92c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int prize(int specialPrizeNumbers[3], int firstPrizeNumbers[3], int myNumber) { | |
int n[3] = {0, 0, 0}; //Number of digits same as the number in every set of firstPrizeNumber in reverse order | |
int i; | |
int dollar = 0; //The prize for this iteration | |
int temp[8]; //Argument of a function, if it's an array, unlike a variable, it will change its value because | |
//it's linked to the address of the array itsel. | |
for(i=0; i<8; i++){ | |
temp[i] = firstPrizeNumbers[i]; | |
//To avoid the aforemetioned situation, create a temporary array for the firstPrizeNumber array, and temp array | |
//will be updated every time function prize is called | |
} | |
for(i = 0; i < 3; i++){ | |
if(myNumber == specialPrizeNumbers[i]){ | |
dollar += 2000000; //If you got jackpot | |
} | |
} | |
for(i = 0; i < 3; i++){ | |
while(myNumber % 10 == temp[i] % 10 && myNumber != 0){ //Checking if last digits are the same and if reached | |
//the end | |
n[i]++; | |
myNumber /= 10; //Next number in reverse order | |
temp[i] /= 10; | |
} | |
} | |
for(i = 0; i < 3; i++){ //Calculate dollar | |
switch(n[i]){ | |
case 1: case 2: | |
break; | |
case 3: | |
dollar += 200; | |
break; | |
case 4: | |
dollar += 1000; | |
break; | |
case 5: | |
dollar += 4000; | |
break; | |
case 6: | |
dollar += 10000; | |
break; | |
case 7: | |
dollar += 40000; | |
break; | |
case 8: | |
dollar += 200000; | |
break; | |
default: | |
break; | |
} | |
} | |
return dollar; | |
} | |
int main() { | |
int i; | |
int specialPrizeNumbers[3]; | |
int firstPrizeNumbers[3]; | |
int myNumber; | |
int totalPrize = 0; | |
for (i = 0; i < 3; i++) | |
scanf("%d", &(specialPrizeNumbers[i])); | |
for (i = 0; i < 3; i++) | |
scanf("%d", &(firstPrizeNumbers[i])); | |
while (scanf("%d", &myNumber) != EOF) | |
totalPrize += prize(specialPrizeNumbers, firstPrizeNumbers, myNumber); | |
printf("%d\n", totalPrize); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment