Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //Robert Millaway
- //8/31
- //Sudokode p1
- #define column_check 1
- #define row_check 2
- #define box_check 3
- #define NONNUMBER_FOUND 4
- int wrong(char *array, int type, int errorLocation);
- int check(char *array);
- int main( char *argv[])
- {
- /* Reading the Matrix from file */
- int c;
- int i = 0, j = 0;
- char matrix[9][9];
- for(i = 0; i < 9; i++)
- {
- char row[10];
- scanf("%s", row);
- for(j = 0; j < 9; j++)
- {
- matrix[i][j] = row[i];
- }
- }
- /* Printing the matrix */
- printf("\n -- sudoku -- \n");
- for (i = 0; i < 9; i++)
- {
- for (j = 0; j < 9; j++)
- printf("%c ", matrix[i][j]);
- printf("\n");
- }
- char buffer[9];
- //column
- for (i = 0; i < 9; i++)
- {
- for (j = 0; j < 9; j++)
- buffer[j] = matrix[i][j];
- if (check(buffer) != 0)
- wrong(buffer, column_check, i);
- }
- //row
- for (j = 0; j < 9; j++)
- {
- for (i = 0; i < 9; i++)
- {
- buffer[i] = matrix[i][j];
- }
- if (check(buffer) != 0)
- wrong(buffer, row_check, j);
- }
- //box
- int count = 0;
- int icnt = 0;
- int jcnt = 0;
- int matcnt = 0;
- for (i = 0; i <= 6; i+= 3)
- {
- for (j = 0; j <= 6; j += 3)
- {
- for (icnt = 0, count = 0; icnt < 3; icnt++)
- {
- for (jcnt = 0; jcnt < 3; jcnt++)
- {
- buffer[count++] = matrix[i+icnt][j+jcnt];
- }
- }
- ++matcount;
- if (check(buffer) != 0)
- wrong(buffer, box_check, matcnt);
- }
- }
- if (flag == 0)
- printf("\n yes :)");
- printf("\n");
- return 0;
- }
- int check(char *array)
- {
- int i, count;
- for (i = 0; i < 9; i++)
- {
- count = i;
- while (count < 9)
- {
- if (array[i] == array[++count])
- return 1;
- }
- }
- return 0;
- }
- int wrong(char *array, int type, int errorLocation)
- {
- int i;
- flag = 1;
- if (type == column_check)
- {
- printf("\n no %d: \n\t", ++errorLocation);
- for (i = 0; i < 9; i++)
- printf("%c ", array[i]);
- }
- else if (type == row_check)
- {
- printf("\n no %d: \n", ++errorLocation);
- for (i = 0; i < 9; i++)
- printf("\n\t %c ", array[i]);
- }
- else if (type == box_check)
- {
- printf("\n no %d: \n", errorLocation);
- for (i = 0; i < 9; i++)
- {
- printf("%c ", array[i]);
- if ((i == 2) || (i == 5))
- printf("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement