Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAXN 100
- int main()
- {
- int z;
- int athroisma_diags1=0,athroisma_diags2=0;
- char* ANSWERS[MAXN];
- char *UNIQUE[MAXN],*DIAG1[MAXN],*DIAG2[MAXN],*MAGIC[MAXN];
- int N,i,j,b=0,athroisma=0,athroisma_rows[MAXN],athroisma_cols[MAXN],apantiseis[MAXN+MAXN];
- int array [MAXN][MAXN];
- int pinakas[MAXN*MAXN];
- int x=0;
- int a,sum;
- scanf("%d",&N);
- while (N >= 100){
- scanf("%d",&N);
- }for (i=0; i<N;i++){
- for (j=0;j<N;j++){
- array[i][j] = 0;}}
- for (i=0; i<N ; i++)
- {
- for (j=0; j<N; j++){
- pinakas[x]= array[i][j];
- x++;
- }
- }
- sum=N*(N*N + 1)/2;
- for (i=0; i<N*N ; i++)
- {
- a=0;
- scanf("%d",&pinakas[i]);
- for (j=0; j<N*N;j++){
- if (pinakas[i]== pinakas[j])
- a++;
- }
- if (a>1)
- { *UNIQUE= "NO";}
- else
- b++;
- }
- if (b==N*N)
- *UNIQUE = "YES";
- x=0;
- for (i=0;i<N;i++)
- {
- for (j=0;j<N;j++){
- array[i][j]= pinakas[x];
- x++;
- }}
- for (i=0; i<N; i++){
- athroisma_rows[i]=0;
- for (j=0; j<N; j++){
- athroisma_rows[i]=athroisma_rows[i]+array[i][j];
- }
- if (athroisma_rows[i]==sum){
- apantiseis[i]=1;
- }
- else{
- apantiseis[i]=0;}
- }
- for (i=0; i<N; i++){
- athroisma_cols[i]=0;
- for (j=0; j<N; j++){
- athroisma_cols[i]=athroisma_cols[i]+array[j][i];
- if (i==j){
- athroisma_diags1=athroisma_diags1+array[i][j];
- }
- if ((i+2+j)==(N+1)){
- athroisma_diags2= athroisma_diags2+array[i][j];
- }
- }
- if (athroisma_cols[i]==sum){
- apantiseis[N+i]=1;
- }
- else{
- apantiseis[N+i]=0;}
- }
- for (i=0;i<N+N;i++){
- if (apantiseis[i]==1){
- ANSWERS[i]="YES";
- }
- else {
- ANSWERS[i]="NO";
- }
- }
- for (i=0;i<N+N;i++)
- {
- if (i <N){
- printf("ROW %d %s\n ",i+1,ANSWERS[i]);
- }
- else {
- printf("COLUMN %d %s\n",i+1-N,ANSWERS[i]);
- }
- }
- if (athroisma_diags1==sum){
- printf("DIAG1 YES\n");
- }
- else
- {
- printf("DIAG1 NO\n");
- }
- if (athroisma_diags2==sum){
- printf("DIAG2 YES\n");
- }
- else
- {
- printf("DIAG2 NO\n");
- }
- z=0;
- printf("UNIQUE %s\n",*UNIQUE);
- for (i=0; i<N+N; i++){
- if (strcmp(ANSWERS[i],"YES")== 0)
- z++;
- }
- if (z==2*N && (strcmp(*UNIQUE,"YES")== 0) && athroisma_diags2==sum && athroisma_diags1==sum)
- {
- printf("MAGIC YES\n");
- }
- else
- printf("MAGIC NO\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement