1098 - I2P CS 2016 Chen HW11 Scoreboard

Time

2016/12/09 00:00:00 2016/12/15 13:20:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10308 2048
10369 sosort

10308 - 2048   

Description

The game of 2048 is very simple. Given a 4x4 map containing tiles and spaces. The values are displayed on the tiles, and the spaces are displayed as 0. The values of tiles are always the power of 2. For example,
    2    2   64  128
    4    0    4   16
    4    4    4    4
    0    0    2    0

is a valid map.

We are able to slide the tiles in the only down direction. The rules of sliding are defined as follows:
1. All tiles slide past spaces. If you move the puzzle to the bottom, all spaces will end up on the top.
2. After sliding to collapse spaces, any tiles with the same value combine and the remainder of the column slides to fill in the hole.
3. One tile can only combine(be combined) once.
4. The combination always starts from the bottom.
5. Contrary to the famous game of 2048, there are no new tiles generated.

For instance, if we have the map above, after we slide the tiles once, the map becomes
    0    0    0    0
    0    0   64  128
    2    2    8   16
    8    4    2    4


Your job is to output the number of spaces for each column after sliding the tiles.

Hint:

#include <stdio.h>

#define WIDTH 4
#define HEIGHT 4

int map[HEIGHT][WIDTH];

void collapse(){
    /* your code here */
}

void slide(){
    /* your code here */
}

void show(){
    /* your code here */
}

int main()
{
    int N, d;
    int i, j;

    scanf("%d", &N);
    for(i = 0; i < HEIGHT; i++){
        for(j = 0; j < WIDTH; j++){
            scanf("%d", &map[i][j]);
        }
    }

    for(i = 0; i < N; i++){
        slide();
    }

    show();

    return 0;
}

Input

N (the count of slides)
The map

Output

The number of spaces of each column

Use "%d " to print each number. Print a newline '\n' at the end.
Note that the value of tiles will not exceed 8192.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10369 - sosort   

Description

The input contains three integers of the same length (same number of digits).
For example,
3412
5232
9128

For each integer, we rearrange its digits from small to large and produce a new integer. Therefore, the three integers above become
1234
2235
1289

The output shows the three integers in an increasing order, that is,
1234
1289
2235


You may use the following piece of code:

/* Using bubble sort to rearrange an array A[n] */

for (i = 0; i < n; i++) {
   for (j = 1; j < n; j++) {
      if (A[j-1] > A[j]) {
         /* swap A[j-1] A[j] */
      }
   }
}

Input

The length of three integers, 1 ≤ length ≤ 9.
Three integers of the same length.

Output

Three rearranged integers in an increasing order.
Print a newline at the end of each integer.

Sample Input  Download

Sample Output  Download

Tags




Discuss