Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- typedef struct{
- int x;
- int y;
- }pos;
- int main()
- {
- int n,k;
- pos player[4],a,b,c,d;
- scanf("%d %d",&n,&k);
- int table[n][n];for(int i=0;i<n;i++)for(int j=0;j<n;j++)table[i][j] = 0;
- table[0][n-1] = 'a'; player[0].x = n-1 , player[0].y = 0;
- table[n-1][n-1] = 'b'; player[1].x = n-1,player[1].y = n-1;
- table[n-1][0] = 'c'; player[2].x = 0,player[2].y = n-1;
- table[0][0] = 'd'; player[3].x = 0,player[3].y = 0;
- int score[4];for(int i=0;i<4;i++)score[i] = 0;
- char move[4][k];
- for(int i=0;i<4;i++){
- for(int j=0;j<k;j++){
- scanf(" %c",&move[i][j]);
- }
- }
- /* for(int I=0;I<n;I++){
- for(int J=0;J<n;J++){
- printf("%d ",table[I][J]);
- }
- printf("\n");
- }
- printf("\n");*/
- /* printf("\n");
- for(int i=0;i<4;i++){
- printf("%c : ",i+'a');
- for(int j=0;j<k;j++){
- printf("%c ",move[i][j]);
- }
- printf("\n");
- }*/
- for(int j=0;j<k;j++){
- for(int i=0;i<4;i++){
- switch (move[i][j]){
- case 'N':{
- if(player[i].y - 1 >= 0 && (table[player[i].y - 1][player[i].x] >= 0 && table[player[i].y - 1][player[i].x] <= 4)){
- table[player[i].y][player[i].x] = i+1;
- table[player[i].y - 1][player[i].x] = 'a'+i;
- player[i].x = player[i].x;
- player[i].y = player[i].y - 1;
- }
- break;
- }
- case 'S':{
- if(player[i].y + 1 < n && (table[player[i].y + 1][player[i].x] >= 0 && table[player[i].y + 1][player[i].x] <= 4)){
- table[player[i].y][player[i].x] = i+1;
- table[player[i].y + 1][player[i].x] = 'a'+i;
- player[i].x = player[i].x;
- player[i].y = player[i].y + 1;
- }
- break;
- }
- case 'W':{
- if(player[i].x - 1 >= 0 && (table[player[i].y][player[i].x - 1] >= 0 && table[player[i].y][player[i].x - 1] <= 4)){
- table[player[i].y][player[i].x] = i+1;
- table[player[i].y][player[i].x - 1] = 'a'+i;
- player[i].x = player[i].x - 1;
- player[i].y = player[i].y;
- }
- break;
- }
- case 'E':{
- if(player[i].x + 1 < n && (table[player[i].y][player[i].x + 1] >= 0 && table[player[i].y][player[i].x + 1] <= 4)){
- table[player[i].y][player[i].x] = i+1;
- table[player[i].y][player[i].x + 1] = 'a';
- player[i].x = player[i].x + 1;
- player[i].y = player[i].y;
- }
- break;
- }
- }
- /*
- for(int I=0;I<n;I++){
- for(int J=0;J<n;J++){
- printf("%d ",table[I][J]);
- }
- printf("\n");
- }
- printf("\n");*/
- }
- }
- int max = -1,maxi,maxc = 0;
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++){
- if(table[i][j] == 0){
- printf("No");
- return 0;
- }
- if(table[i][j]>='a'){
- table[i][j] = (table[i][j]-'a')+1;
- }
- score[table[i][j]-1]++;
- if(score[table[i][j]-1]>max){
- max = score[i];
- }
- }
- }
- // printf("score : ");
- for(int i=0;i<4;i++){
- if(score[i]>max){
- max = score[i];
- }
- // printf("%d ",score[i]);
- }
- // printf("\n");
- for(int i=0;i<4;i++){
- if(score[i] == max){
- maxc++;
- }
- }
- printf("%d %d\n",maxc,max);
- for(int i=0;i<4;i++){
- if(score[i] == max){
- printf("%d\n",i+1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment