cLanguage code-up algorithm problem questions

Asked 2 years ago, Updated 2 years ago, 43 views

First of all, this question itself is about what's on code-up (other sites), so I don't know if I can ask this question... I'm worried, but I'm so curious. I'll upload it <

The problem is as follows

Question number 1509

There is a 10*10 size board.

Each horse advances from the bottom to the top.

Obstacles are represented by non-zero numbers, and if they are greater than 0, they are block obstacles, if they are less than 0, they are pit obstacles, and if they are 0, they are flat.

Implement a program to determine the survival of each horse when the information on the 10*10 board is entered, and if there is a horse under each vertical line, 1 or 0 is entered.

Input Information on the board of 10*10 is input.

The position of each horse is entered in the 11th line (1:Yes, 0:None)

Output "Vertical line number crash",

when a block obstacle fails

If you fall into a pit and fail, "vertical line number fall",

If it passes safely, it prints "Vertical Line Number Safe".

(However, the line without words does not output any results.)

Input Example

0 0 0 0 0 0 0 0 0 0 
0 2 0 0 0 0 0 0 0 0 
0 0 -1 0 0 0 0 0 2 0 
0 0 0 0 0 0 0 6 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 -4 2 0 0 0 
0 0 2 0 0 0 0 0 0 0 
0 0 0 0 3 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
1 1 0 0 1 1 0 1 0 1 

Sample Output

1 safe
2 crash
5 crash
6 fall
8 crash
10 safe

Help

The first line passed safely.

The horse in line 2 was hit by a size 2 obstacle and failed.

Line 5 hits 3 obstacles and fails

Line 6 fell out of the -4 obstacle and failed

Line 8 hits 6 obstacles and fails

The 10th line passes safely.

==============================================================================

This is the code I made

#include <stdio.h>
int main(){
    int ar[11][10];
    int i,j;
    int count=0;

    for(i=0;i<11;i++){
        for(j=0;j<10;j++){
            scanf("%d",&ar[i][j]);
        }
    }

    for(i=0;i<10;i++){
        if(ar[10][i]==1){
            count=0;
            for(j=0;j<10;j++){
                if(ar[j][i]>0){
                    printf("%d crash\n",i+1);
                    break;
                } 
                else if(ar[j][i]<0){
                    printf("%d fall\n",i+1);
                    break;
                }
                count++;
            }
            if(count==10){
                printf("%d safe\n",i+1);
            }
        }
    }
    return 0;
}

=================================================================================

It keeps getting stuck in test case number 3, but I think I've seen it for about three days (t) I don't understand where to fix it anymore and where there is an error

Error content is

==============================================

Enter:

-1 0 0 0 0 0 0 0 -1 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
1 1 1 1 1 1 1 1 1 1 
1 1 0 0 1 1 0 1 0 1 

Answer

1 crash
2 crash
5 crash
6 crash
8 crash
10 crash

Output results

1 fall
2 crash
5 crash
6 crash
8 crash
10 crash

==============================================================================

Here it is....

I hope I made a mistake... Otherwise, I will break the time and mental state I spent on this problem, so I can't study anymore

c algorithm

2022-09-22 18:21

1 Answers

Here's the condition of the problem.

Each horse advances from the bottom to the top.

However, j is traveling from 0 to 9.

That means the horses are advancing from top to bottom.

In other words, ar[j][i]ar[9][0], ar[8][0], ... It's not being checked in order, it's being reversed.

If you look at the wrong output carefully, for example, you can see that horse number 1 is missing from ar[0][0][0]-1 and marked 1 fall.

for (int j = 9; j > = 0; j--) and try again.

PS. I used the term "horse one," but Horse" is not an animal here. 1 minute common sense in Korean.


2022-09-22 18:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.