Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 6
- #define STORAGE 2
- #define SCORES 6
- int main (void){
- int num[SIZE];
- int total = 0;
- int i;
- int matchScore = 0;
- int sequenceScore = 0;
- int score = 0;
- printf("Please enter 6 integers: ");
- for (i = 0; i < SIZE; i++){
- scanf("%d", &num[i]);
- total = total + num[i];
- }
- /*----------------------ERROR CHECKS---------------------------*/
- //Check if valid 1->9 integers given and if integers are in ascending order
- for (i = 0; i < SIZE - 1; i++){
- if ((num[i] > num[i+1]) || (num[i] < 1) || (num[i] > 9)){
- printf("Invalid input: 6 integers from 1 to 9 must be supplied in ascending order.\n");
- return 0;
- }
- }
- /*----------------------MATCH RULE-----------------------------------------*/
- int n;
- int count = 1;
- int highestCurCount = 0;
- int overallCount = 0;
- int largestRepeatingInt = 0;
- for (i = 0; i < SIZE; i++){
- for (n = i+1; n < SIZE; n++){
- if (num[i] == num[n]){
- count++;
- highestCurCount = count;
- } else {
- count = 1;
- }
- }
- count = 1;
- if (highestCurCount >= overallCount){
- overallCount = highestCurCount;
- largestRepeatingInt = i;
- }
- highestCurCount = 1;
- }
- /*----------------------SEQUENCE RULE-----------------------------------------*/
- int longestSequence[SIZE][SIZE] = {{0}};
- int sequenceLength1=0;
- int sequenceStart = 0;
- int j, k;
- int newLength[3] = {0};
- int finalLength = 0;
- int sequenceRow[3] = {0};
- n = 0;
- for (i = 0; i < SIZE; i++){
- if (num[i+1] == num[i]){
- // Waiting for the next valid number
- } else if (num[i] + 1 == num[i+1]){
- longestSequence[n][sequenceLength1] = num[i];
- longestSequence[n][sequenceLength1 + 1] = num[i+1];
- sequenceLength1++; // sequenceLength1 is the current sequence length
- } else {
- sequenceLength1 = 0;
- n++;
- }
- }
- n = 0;
- j = 0;
- k = 0;
- count = 0;
- for (i = 0; i < SIZE; i++){
- for (j = 0; j < SIZE; j++){
- if (longestSequence[i][0] == 0){
- j = SIZE;
- count = 0;
- } else if (longestSequence[i][j] != 0) {
- count++;
- if(j == 5){
- sequenceRow[k] = i;
- k++;
- newLength[n] = count;
- n++;
- }
- } else {
- sequenceRow[k] = i;
- k++;
- newLength[n] = count;
- count = 0;
- n++;
- j = SIZE;
- }
- }
- }
- if (newLength[0] > newLength[1]){
- if (newLength[0] > newLength[2]){
- finalLength = newLength[0];
- sequenceStart = sequenceRow[0];
- } else if (newLength[0] <= newLength[2]){
- finalLength = newLength[2];
- sequenceStart = sequenceRow[2];
- }
- } else if (newLength[1] > newLength[2]){
- finalLength = newLength[1];
- sequenceStart = sequenceRow[1];
- } else {
- finalLength = newLength[2];
- sequenceStart = sequenceRow[2];
- }
- /*-----------------------SCORES-----------------------------------------*/
- sequenceScore = (finalLength * longestSequence[sequenceStart][finalLength-1]) + (15 + finalLength);
- matchScore = (overallCount * num[largestRepeatingInt]) + (15 + (overallCount*2));
- printf("Rule ");
- if (sequenceScore <= matchScore){
- score = matchScore;
- printf("match-%d(%d) - score - %d.\n", overallCount, num[largestRepeatingInt], score);
- } else if (matchScore < sequenceScore){
- score = sequenceScore;
- printf("sequence-%d - score - %d.\n", longestSequence[sequenceStart][finalLength-1], score);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement