Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAXN 100
  5. int main()
  6. {
  7. int z;
  8. int athroisma_diags1=0,athroisma_diags2=0;
  9. char* ANSWERS[MAXN];
  10. char *UNIQUE[MAXN],*DIAG1[MAXN],*DIAG2[MAXN],*MAGIC[MAXN];
  11. int N,i,j,b=0,athroisma=0,athroisma_rows[MAXN],athroisma_cols[MAXN],apantiseis[MAXN+MAXN];
  12. int array [MAXN][MAXN];
  13. int pinakas[MAXN*MAXN];
  14. int x=0;
  15. int a,sum;
  16. scanf("%d",&N);
  17. while (N >= 100){
  18. scanf("%d",&N);
  19. }for (i=0; i<N;i++){
  20. for (j=0;j<N;j++){
  21.  
  22. array[i][j] = 0;}}
  23. for (i=0; i<N ; i++)
  24. {
  25. for (j=0; j<N; j++){
  26. pinakas[x]= array[i][j];
  27. x++;
  28. }
  29. }
  30. sum=N*(N*N + 1)/2;
  31. for (i=0; i<N*N ; i++)
  32. {
  33. a=0;
  34. scanf("%d",&pinakas[i]);
  35. for (j=0; j<N*N;j++){
  36. if (pinakas[i]== pinakas[j])
  37. a++;
  38. }
  39. if (a>1)
  40. { *UNIQUE= "NO";}
  41. else
  42. b++;
  43.  
  44.  
  45. }
  46. if (b==N*N)
  47. *UNIQUE = "YES";
  48.  
  49. x=0;
  50. for (i=0;i<N;i++)
  51. {
  52. for (j=0;j<N;j++){
  53. array[i][j]= pinakas[x];
  54. x++;
  55. }}
  56. for (i=0; i<N; i++){
  57. athroisma_rows[i]=0;
  58. for (j=0; j<N; j++){
  59. athroisma_rows[i]=athroisma_rows[i]+array[i][j];
  60. }
  61. if (athroisma_rows[i]==sum){
  62. apantiseis[i]=1;
  63. }
  64.  
  65. else{
  66. apantiseis[i]=0;}
  67. }
  68. for (i=0; i<N; i++){
  69. athroisma_cols[i]=0;
  70. for (j=0; j<N; j++){
  71. athroisma_cols[i]=athroisma_cols[i]+array[j][i];
  72. if (i==j){
  73. athroisma_diags1=athroisma_diags1+array[i][j];
  74. }
  75. if ((i+2+j)==(N+1)){
  76. athroisma_diags2= athroisma_diags2+array[i][j];
  77. }
  78. }
  79. if (athroisma_cols[i]==sum){
  80. apantiseis[N+i]=1;
  81. }
  82.  
  83. else{
  84. apantiseis[N+i]=0;}
  85. }
  86. for (i=0;i<N+N;i++){
  87. if (apantiseis[i]==1){
  88. ANSWERS[i]="YES";
  89. }
  90. else {
  91. ANSWERS[i]="NO";
  92. }
  93. }
  94. for (i=0;i<N+N;i++)
  95. {
  96. if (i <N){
  97. printf("ROW %d %s\n ",i+1,ANSWERS[i]);
  98. }
  99. else {
  100. printf("COLUMN %d %s\n",i+1-N,ANSWERS[i]);
  101. }
  102. }
  103.  
  104. if (athroisma_diags1==sum){
  105. printf("DIAG1 YES\n");
  106. }
  107. else
  108. {
  109. printf("DIAG1 NO\n");
  110. }
  111. if (athroisma_diags2==sum){
  112. printf("DIAG2 YES\n");
  113. }
  114. else
  115. {
  116. printf("DIAG2 NO\n");
  117. }
  118. z=0;
  119. printf("UNIQUE %s\n",*UNIQUE);
  120. for (i=0; i<N+N; i++){
  121. if (strcmp(ANSWERS[i],"YES")== 0)
  122. z++;
  123. }
  124. if (z==2*N && (strcmp(*UNIQUE,"YES")== 0) && athroisma_diags2==sum && athroisma_diags1==sum)
  125. {
  126. printf("MAGIC YES\n");
  127. }
  128. else
  129. printf("MAGIC NO\n");
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement