Advertisement
Guest User

Full1

a guest
Apr 27th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define SIZE 6
  4. #define STORAGE 2
  5. #define SCORES 6
  6.  
  7. int main (void){
  8.  
  9. int num[SIZE];
  10. int total = 0;
  11. int i;
  12. int matchScore = 0;
  13. int sequenceScore = 0;
  14. int score = 0;
  15.  
  16. printf("Please enter 6 integers: ");
  17. for (i = 0; i < SIZE; i++){
  18. scanf("%d", &num[i]);
  19. total = total + num[i];
  20. }
  21.  
  22. /*----------------------ERROR CHECKS---------------------------*/
  23. //Check if valid 1->9 integers given and if integers are in ascending order
  24. for (i = 0; i < SIZE - 1; i++){
  25. if ((num[i] > num[i+1]) || (num[i] < 1) || (num[i] > 9)){
  26. printf("Invalid input: 6 integers from 1 to 9 must be supplied in ascending order.\n");
  27. return 0;
  28. }
  29. }
  30.  
  31. /*----------------------MATCH RULE-----------------------------------------*/
  32.  
  33. int n;
  34. int count = 1;
  35. int highestCurCount = 0;
  36. int overallCount = 0;
  37. int largestRepeatingInt = 0;
  38.  
  39. for (i = 0; i < SIZE; i++){
  40. for (n = i+1; n < SIZE; n++){
  41. if (num[i] == num[n]){
  42. count++;
  43. highestCurCount = count;
  44. } else {
  45. count = 1;
  46. }
  47.  
  48. }
  49. count = 1;
  50. if (highestCurCount >= overallCount){
  51. overallCount = highestCurCount;
  52. largestRepeatingInt = i;
  53. }
  54. highestCurCount = 1;
  55. }
  56.  
  57. /*----------------------SEQUENCE RULE-----------------------------------------*/
  58.  
  59. int longestSequence[SIZE][SIZE] = {{0}};
  60. int sequenceLength1=0;
  61. int sequenceStart = 0;
  62. int j, k;
  63. int newLength[3] = {0};
  64. int finalLength = 0;
  65. int sequenceRow[3] = {0};
  66.  
  67. n = 0;
  68. for (i = 0; i < SIZE; i++){
  69. if (num[i+1] == num[i]){
  70. // Waiting for the next valid number
  71. } else if (num[i] + 1 == num[i+1]){
  72. longestSequence[n][sequenceLength1] = num[i];
  73. longestSequence[n][sequenceLength1 + 1] = num[i+1];
  74.  
  75. sequenceLength1++; // sequenceLength1 is the current sequence length
  76. } else {
  77. sequenceLength1 = 0;
  78. n++;
  79. }
  80. }
  81. n = 0;
  82. j = 0;
  83. k = 0;
  84. count = 0;
  85. for (i = 0; i < SIZE; i++){
  86. for (j = 0; j < SIZE; j++){
  87. if (longestSequence[i][0] == 0){
  88. j = SIZE;
  89. count = 0;
  90. } else if (longestSequence[i][j] != 0) {
  91. count++;
  92. if(j == 5){
  93. sequenceRow[k] = i;
  94. k++;
  95. newLength[n] = count;
  96. n++;
  97. }
  98. } else {
  99. sequenceRow[k] = i;
  100. k++;
  101. newLength[n] = count;
  102. count = 0;
  103. n++;
  104. j = SIZE;
  105. }
  106. }
  107. }
  108.  
  109. if (newLength[0] > newLength[1]){
  110. if (newLength[0] > newLength[2]){
  111. finalLength = newLength[0];
  112. sequenceStart = sequenceRow[0];
  113. } else if (newLength[0] <= newLength[2]){
  114. finalLength = newLength[2];
  115. sequenceStart = sequenceRow[2];
  116. }
  117. } else if (newLength[1] > newLength[2]){
  118. finalLength = newLength[1];
  119. sequenceStart = sequenceRow[1];
  120. } else {
  121. finalLength = newLength[2];
  122. sequenceStart = sequenceRow[2];
  123. }
  124.  
  125. /*-----------------------SCORES-----------------------------------------*/
  126.  
  127. sequenceScore = (finalLength * longestSequence[sequenceStart][finalLength-1]) + (15 + finalLength);
  128. matchScore = (overallCount * num[largestRepeatingInt]) + (15 + (overallCount*2));
  129.  
  130. printf("Rule ");
  131. if (sequenceScore <= matchScore){
  132. score = matchScore;
  133. printf("match-%d(%d) - score - %d.\n", overallCount, num[largestRepeatingInt], score);
  134. } else if (matchScore < sequenceScore){
  135. score = sequenceScore;
  136. printf("sequence-%d - score - %d.\n", longestSequence[sequenceStart][finalLength-1], score);
  137. }
  138.  
  139. return 0;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement