1546 - I2P (I) 2018_Chen_HW5 Scoreboard

Time

2018/11/22 00:00:00 2018/11/29 13:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11665 World war
11686 more simple exercise of pointer on array
11691 pC - Ponds

11665 - World war   

Description

Country H upgrades the tank in order to defeat Country T in world war. 

You're a soldier in great Country H and have received secret tasks : Collect the military secrets related to Country T

 

You wil get a map of Country T like this:

              

 is your tank with size 3x3 (xox is the head of the tank). 

'$' represents a military secrets,  '#' represents the wall, '^' represents the hill.

If you tank (3x3 body) is overlaped with the '$', you will pick it up ($ can't be counted again). If '#' or '^' is in front of the tank(in front of the xox, tank's front part), you can not move. Military secrets' position don't appear at initial tank's position.

The tank has four forward directions(South, East, North, West). Its direction is where xox heads. Notice that the upper of the map is the North, and the initial direction of tank is not always North.

And you will receive a sequence of instructions, which contains (takes a step along the tank's head direction), R(tank's head turns right), and L(tank's head turns left). Instructions like R and L only change tank's head direction, and don't affect tank's position(would not cause moving). 

 

Since the tank is upgraded, the tank can now execute instruction J (takes two step along the tanks head direction). However, you should NOT execute J when the tank may collides with hill or wall (in this case, you pick up nothing, and stand still at the original position).

 

Your will collect the military secrets within the valid instruction as many as possible. Then report the number of it to your boss, HT, immediately !

Fighting ! 

 

There are sample codes for you:

#include <stdio.h>
#include <string.h>

#define EAST 0
#define SOUTH 1
#define WEST 2
#define NORTH 3

char map[100][100];
char actions[100]={};
int coin_amount = 0;

// tank's initial direction
char init_dir;
// tank's direction now
int dir_now;
// tank's center x and y
int center_x, center_y;

void decide_initial_direction()
{
    /// Decide tank's initial direction
    /// Using init_dir
    /// To determine dir_now

 

}

void take_a_step()
{
    if (dir_now == NORTH){
        /// Detect wall first
        if ( ??? ){

        }
        /// And then detect hill
        else if (( ??? )) {

        }
        /// If there is no obstacle, take a step
        else {

        }
    }
    else if (dir_now == SOUTH){

    }
    else if (dir_now == EAST){

    }
    else if (dir_now == WEST){

    }
}

void pick_the_coins()
{
    int j, k;
    for (j = center_x - 1; j <= center_x + 1; j++){
        for (k = center_y - 1; k <= center_y + 1; k++){
            /// determine whether there are coins under the tank

 

        }
    }
}

void turn_right()
{
    /// Change direction depending on dir_now
}

 

void turn_left()
{
    /// Change direction depending on dir_now
}

int main()
{
    int i, j, k, rows, cols;
    int actions_number;
    int component = 0;

    /// Raed problem's input
    scanf("%d %d %d %c", &rows, &cols, &actions_number, &init_dir);
    while (getchar() != '\n');
    for (i = 0; i < actions_number; i++){
        scanf("%c", &actions[i]);
    }

    /// Read map
    for (i = 1; i <= rows; i++){
        while (getchar() != '\n');
        for (j = 1; j <= cols; j++){
            scanf("%c", &map[i][j]);
            /// Find tank's center x and y
            if (((map[i][j]) == 'x') || ((map[i][j]) == 'o') || ((map[i][j]) == 'O')){
                component++;
                if (component == 5){
                    center_x = i;
                    center_y = j;
                }
            }
        }
    }

    decide_initial_direction();

    for (i = 0; i < actions_number; i++){
        if (actions[i] == 'F'){
            take_a_step();
            pick_the_coins();
        }

        else if (  ){

           /* TODO : Implement the instruction "J" here */

       }         
        else{
            if (actions[i] == 'R'){
                turn_right();
            }
            if (actions[i] == 'L'){
                turn_left();
            }
        }
    }

    printf("%d\n", coin_amount);

    return 0;
}

 

Input

The first line of the input contains four things: 

1. The rows of the map (0 < rows < 100)

2. The columns of the map (0 < cols < 100)

3. The total length of instructions (0 < instructions's length < 100)

4. The initial tank's direction(N, S, E, W)

The second line is the content of instructions.

For the next lines, they illustrate the map.

Output

The number of military informations you get. (printf "\n" in the end)

Sample Input  Download

Sample Output  Download

Tags




Discuss




11686 - more simple exercise of pointer on array   

Description

In this exercise, you should exchange the content of two given one dimensional integer arrays with same length.

We have written the code about reading the size and the content of arrays, and we want to pass them to a function for getting the final answer. What you need is helping us to complete the function. 

What input into the function is two pointers representing the two arrays and the length of array, and the function has to exchange the content of the two arrays.

For more specific, you only need to implement the following function:

#include <stdio.h>
#include "function.h"
void array_exchanger(int* array_a, int* array_b, int length) {

     // your code
}

The .c and .h file below might be helpful if you want to know how the function and the whole program works.

Input

The input may have 3 lines of input.

The very first line is a number, representing the length of 2 arrays.

The second and the third lines are several integers, representing the content of 2 arrays.

Output

The content in two arrays after exchanged.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11686.c

Partial Judge Header

11686.h

Tags

pointer



Discuss




11691 - pC - Ponds   

Description

Writer: jjjjj19980806       Description: pclightyear       Difficulty: ★★☆☆☆

Frank Lin likes to go mountain climbing. Every time before he goes mountain climbing, he needs to look up the map to plan for the route. According to Frank’s experience, it is very important to locate the position of ponds, since it is usually the best place for resting. Now, Frank gives you a map sized m ✕ n consists of only two symbols '~' and '.', representing water and land, respectively. Frank wonders how many ponds (consecutive position of water) are there on the map.

If you can help Frank solve this problem, maybe he will teach you how to build a tent within five minutes.

Input

The first line contains two integers mn, representing the size of the map Frank gives to you.

The next m lines contain n characters, either '~' or '.', representing the status of position aij.

It is guaranteed that :

  • 1 ≤ m, n ≤ 1000

Output

Please output the number of ponds on the map.

Sample Input  Download

Sample Output  Download

Tags




Discuss