SuitNdtie

Conquerer PROG 1033

Mar 9th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. #include<stdio.h>
  2. typedef struct{
  3.     int x;
  4.     int y;
  5. }pos;
  6. int main()
  7. {
  8.     int n,k;
  9.     pos player[4],a,b,c,d;
  10.     scanf("%d %d",&n,&k);
  11.     int table[n][n];for(int i=0;i<n;i++)for(int j=0;j<n;j++)table[i][j] = 0;
  12.     table[0][n-1] = 'a';  player[0].x = n-1 , player[0].y = 0;
  13.     table[n-1][n-1] = 'b';  player[1].x = n-1,player[1].y = n-1;
  14.     table[n-1][0] = 'c';  player[2].x = 0,player[2].y = n-1;
  15.     table[0][0] = 'd';  player[3].x = 0,player[3].y = 0;
  16.     int score[4];for(int i=0;i<4;i++)score[i] = 0;
  17.     char move[4][k];
  18.     for(int i=0;i<4;i++){
  19.         for(int j=0;j<k;j++){
  20.             scanf(" %c",&move[i][j]);
  21.         }
  22.     }
  23. /*  for(int I=0;I<n;I++){
  24.                 for(int J=0;J<n;J++){
  25.                     printf("%d ",table[I][J]);
  26.                 }
  27.                 printf("\n");
  28.             }
  29.     printf("\n");*/
  30. /*  printf("\n");
  31.     for(int i=0;i<4;i++){
  32.         printf("%c : ",i+'a');
  33.         for(int j=0;j<k;j++){
  34.             printf("%c ",move[i][j]);
  35.         }
  36.         printf("\n");
  37.     }*/
  38.     for(int j=0;j<k;j++){
  39.         for(int i=0;i<4;i++){
  40.             switch (move[i][j]){
  41.                 case 'N':{
  42.                     if(player[i].y - 1 >= 0 && (table[player[i].y - 1][player[i].x] >= 0 && table[player[i].y - 1][player[i].x] <= 4)){
  43.                         table[player[i].y][player[i].x] = i+1;
  44.                         table[player[i].y - 1][player[i].x] = 'a'+i;
  45.                         player[i].x = player[i].x;
  46.                         player[i].y = player[i].y - 1;
  47.                     }
  48.                     break;
  49.                 }
  50.                 case 'S':{
  51.                     if(player[i].y + 1 < n && (table[player[i].y + 1][player[i].x] >= 0 && table[player[i].y + 1][player[i].x] <= 4)){
  52.                         table[player[i].y][player[i].x] = i+1;
  53.                         table[player[i].y + 1][player[i].x] = 'a'+i;
  54.                         player[i].x = player[i].x;
  55.                         player[i].y = player[i].y + 1;
  56.                     }
  57.                     break;
  58.                 }
  59.                 case 'W':{
  60.                     if(player[i].x - 1 >= 0 && (table[player[i].y][player[i].x - 1] >= 0 && table[player[i].y][player[i].x - 1] <= 4)){
  61.                         table[player[i].y][player[i].x] = i+1;
  62.                         table[player[i].y][player[i].x - 1] = 'a'+i;
  63.                         player[i].x = player[i].x - 1;
  64.                         player[i].y = player[i].y;
  65.                     }
  66.                     break;
  67.                 }
  68.                 case 'E':{
  69.                     if(player[i].x + 1 < n && (table[player[i].y][player[i].x + 1] >= 0 && table[player[i].y][player[i].x + 1] <= 4)){
  70.                         table[player[i].y][player[i].x] = i+1;
  71.                         table[player[i].y][player[i].x + 1] = 'a';
  72.                         player[i].x = player[i].x + 1;
  73.                         player[i].y = player[i].y;
  74.                     }
  75.                     break;
  76.                 }
  77.             }
  78.             /*
  79.             for(int I=0;I<n;I++){
  80.                 for(int J=0;J<n;J++){
  81.                     printf("%d ",table[I][J]);
  82.                 }
  83.                 printf("\n");
  84.             }
  85.             printf("\n");*/
  86.         }
  87.     }
  88.     int max = -1,maxi,maxc = 0;
  89.     for(int i=0;i<n;i++){
  90.         for(int j=0;j<n;j++){
  91.             if(table[i][j] == 0){
  92.                 printf("No");
  93.                 return 0;
  94.             }
  95.             if(table[i][j]>='a'){
  96.                 table[i][j] = (table[i][j]-'a')+1;
  97.             }
  98.             score[table[i][j]-1]++;
  99.             if(score[table[i][j]-1]>max){
  100.                 max = score[i];
  101.             }
  102.         }
  103.     }
  104. //  printf("score : ");
  105.     for(int i=0;i<4;i++){
  106.         if(score[i]>max){
  107.                 max = score[i];
  108.             }
  109.     //  printf("%d ",score[i]);
  110.     }
  111. //  printf("\n");
  112.     for(int i=0;i<4;i++){
  113.         if(score[i] == max){
  114.             maxc++;
  115.         }
  116.     }
  117.     printf("%d %d\n",maxc,max);
  118.     for(int i=0;i<4;i++){
  119.         if(score[i] == max){
  120.             printf("%d\n",i+1);
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment