11290 - Moving Cars(4 direction)   

Description

Given the position of N cars on a map, we have to list the valid moves of each car along 4 directions (i.e. right, down, left and up).

Note that all cars can move horizontally and vertically.

For example, a map with 10 cars is shown below:

Given the coordinate of car 2 is 2 3 2 6, it means car 2 occupies the position of (2,3) to (2,6) in the map.

The valid moves of car 2 is 1 0 0 2, which means it can move right 1 grid but can’t move down, left and it can move up 2 grid.

 

HINTS:

function.h

#ifndef FUNCTION_H
#define FUNCTION_H
#define MAP_SIZE 9
#define MAX_CARS 10
#define SPACE '.'

char map[MAP_SIZE][MAP_SIZE];
int cars[MAX_CARS][4];
void list_moves(int);
#endif

main.c

#include <stdio.h>
#include "function.h"
int main(void)
{
    int i,j,k;
    int num_cars;

    scanf("%d",&num_cars);
    //reset map
    for (i=0; i<MAP_SIZE; i++) {
        for (j=0; j<MAP_SIZE; j++) {
            map[i][j] = SPACE;
        }
    }
    //read coordinates of cars and put them on the map
    for (i=0; i<num_cars; i++) {
        scanf("%d%d%d%d", &cars[i][0], &cars[i][1], &cars[i][2], &cars[i][3]);
        for (j=cars[i][0]; j<=cars[i][2]; j++) {
            for (k=cars[i][1]; k<=cars[i][3]; k++) {
                map[j][k] = i+'0';
            }
        }
    }
    list_moves(num_cars);

    return 0;
}

 

Input

The first line is a number N (1<=N<=10), which means the total number of cars.

The following N lines are the coordinates of all cars.

Each line consists of 4 numbers. The first two numbers are the row and column of the head of the car. The other two numbers are the row and column of the tail of the car.

Output

Print out the valid moves of the cars in each line.

Each line consists of 4 number, the valid moves along right, down, left and up.

All of the numbers in the same line are separated by a space, and there is a '\n' at the end of each line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11290.c

Partial Judge Header

11290.h

Tags




Discuss