Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. /*
  2. */
  3.  
  4.  
  5.  
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include <string.h>
  9. #define M 9
  10. #define N 7
  11.  
  12. int plegma[9][9];
  13.  
  14.  
  15. void eisagwgi() {
  16. int i,j,akeraioi;
  17.  
  18. for (i=0; i<M; i++) {
  19. for (j=0; j<M; j++) {
  20. scanf("%d ", &akeraioi); /*whitespace stin arxi keno i meta??*/
  21. plegma[i][j]=akeraioi;
  22. }
  23. }
  24. }
  25.  
  26.  
  27.  
  28.  
  29. void ektypwsi() {
  30. int i,j,k;
  31.  
  32. for (i=0; i<M; i++) {
  33. for (j=0; j<M; j++) {
  34. scanf("%d", &plegma[i][j]);
  35. }
  36. }
  37.  
  38.  
  39. for (j=0; j<M; j++) {
  40. printf(" %d ", j );
  41. if (j==2) {
  42. printf(" ");
  43. }
  44. if (j==5) {
  45. printf(" ");
  46. }
  47. }
  48.  
  49.  
  50. printf("\n=======================================\n");
  51.  
  52.  
  53. for (i=0; i<18; i++) {
  54.  
  55. if ( (i%2==1) && (i!=5) && (i!=11) && (i!=17) ) {
  56. printf("---------------------------------------\n");
  57. }
  58.  
  59. if ( i==5 || i==11 || i==17 ) {
  60. printf("=======================================\n");
  61. }
  62.  
  63. if ( i%2==0 ) {
  64. k=i/2;
  65. for (j=0; j<M; j++) {
  66.  
  67. if (plegma[k][j]!=0) {
  68. if (j!=3 && j!=6) {
  69. printf("| %d ", plegma[k][j]);
  70. }
  71. else {
  72. printf("|| %d ", plegma[k][j]);
  73. }
  74. }
  75.  
  76. else {
  77. if (j!=3 && j!=6) {
  78. printf("| ");
  79. }
  80. else {
  81. printf("|| ");
  82. }
  83. }
  84. }
  85.  
  86. if (j==9) {
  87. printf("| %d\n", k);
  88. }
  89. }
  90. }
  91. }
  92.  
  93. int main(int argc, char* argv[]) {
  94.  
  95. int i,grammh,sthlh,arithmos;
  96. char apantisi[N];
  97.  
  98.  
  99.  
  100. eisagwgi();
  101.  
  102.  
  103. /*stadio 2*/
  104.  
  105.  
  106.  
  107. do {
  108. ektypwsi();
  109. printf("What do you want to do?\n");
  110. scanf("%6s", apantisi);
  111. for (i=0; i<N; i++) {
  112. apantisi[i]=tolower(apantisi[i]);
  113. }
  114. if (strcmp(apantisi,"insert")== 0) {
  115. printf("TRY: insert X in (R, C)\n");
  116. scanf("insert %d in %d,%d", &arithmos, &grammh, &sthlh);
  117. if (arithmos<1 || arithmos>9) {
  118. printf("Number out of range.Insert aborted\n");
  119. continue;
  120. }
  121. if (plegma[grammh][sthlh]!=0) {
  122. printf("Non-empty cell. Insert aborted.\n");
  123. continue;
  124. }
  125. if (grammh<0 || grammh>8 || sthlh<0 || sthlh>8) {
  126. printf("Location out of range.Insert aborted\n");
  127. continue;
  128. }
  129. }
  130. else if (strcmp(apantisi,"delete")==0) {
  131. printf("TRY: delete (R, C)\n");
  132. scanf("delete %d,%d", &grammh, &sthlh);
  133. if (grammh<0 || grammh>8 || sthlh<0 || sthlh>8) {
  134. printf("Location out of range.Delete aborted\n");
  135. continue;
  136. }
  137. }
  138. }while (strcmp(apantisi,"quit")!=0);
  139.  
  140. printf("QUITTING");
  141. printf("Thank you! Play again.");
  142.  
  143.  
  144.  
  145. return 0;
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement