fork download
  1. #include <stdio.h>
  2. #define POSSIBLE_POINTS_LENGTH 4
  3.  
  4. int possiblePoints[POSSIBLE_POINTS_LENGTH] = { 3, 6, 7, 8 };
  5.  
  6. int checkIfValid(int score)
  7. {
  8. int i, j;
  9. if (score < 0) return 0;
  10. for (i = 0; i < POSSIBLE_POINTS_LENGTH; ++i)
  11. {
  12. if (score % possiblePoints[i] == 0)
  13. {
  14. return 1;
  15. }
  16. else
  17. {
  18. for (j = 0; j < POSSIBLE_POINTS_LENGTH; ++j)
  19. {
  20. if (checkIfValid(score - possiblePoints[j]))
  21. {
  22. return 1;
  23. }
  24. }
  25. }
  26. }
  27. return 0;
  28. }
  29.  
  30. int main(void) {
  31. int score, isValid;
  32. scanf("%d", &score);
  33. isValid = checkIfValid(score);
  34. if (isValid)
  35. {
  36. printf("Valid Score");
  37. }
  38. else
  39. {
  40. printf("Invalid Score");
  41. }
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 2296KB
stdin
68
stdout
Valid Score