600 - EECS111000_I2P2014_LAB Scoreboard

Time

2014/12/17 08:30:00 2014/12/17 09:50:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10028 Hello World
10042 Lab01
10076 Lab02
10114 Lab03
10151 Lab04
10186 Lab05
10236 Lab06
10267 Lab07
10294 Lab08
10308 2048
10328 Lab10
10364 Lab11

10028 - Hello World   

Description

請印出 "Hello World"

Hint:

#include

int main(){ 
    printf("Hello World");
    return 0; 
}

Input

Output

印出 "Hello World"

Sample Input  Download

Sample Output  Download

Tags




Discuss




10042 - Lab01   

Description

 A number consists of two digits. The sum of the digit in units and the digit in tens is A. If the two digits are interchanged, the new number is B greater than the original number. Find the original number. 

 

Input

 Given two positive intergers A and B. 

Output

 Please output the original number.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10076 - Lab02   

Description

The input will be a floating point number X which has 2 digits on the left of the point, and 3 digits on the right of the point. X consists of digits 1-9 except 0.
Interchange the two sides of point, and map the number to 'A' - 'I'.

Example:
Input: 46.534
after interchanging: 534.46
after mapping: ECD.DF

Hint:
You should do rounding before converting 'float' to 'int'

#include 

int main()
{
    int a;
    float b;

    a = (int) round(b); 
}

Input

Given a floating point number X.

Output

The mapping result.

Note that you do not need to print ‘\n’ at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10114 - Lab03   

Description

The input contains nine integers, and the range of each integer is 1 to 9, for example, 4 3 5 9 8 7 3 6 2. Now, start from the first place, we get the number 4. It indicates that the next number we need to pick is at the 4th place, which is 9. Likewise, we then go to the 9th place and get the number 2. We repeat this process until we go to a place that has already been visited N-1 times. In this example, if N = 2, we will stop at the 7th place and get the number 3. Therefore, along the way we pick nine numbers, 4 9 2 3 5 8 6 7 3, and the output is the sum of these numbers, which is 47.
Note that we always start from the first place.
Other examples: Consider the input 1 9 8 7 6 5 4 3 2, if N = 4, the output should be 3 since we will visit the first place 3 times and then stop. Consider the input 9 2 3 4 5 6 7 8 1, if N = 3, the output should be 20.

Input

N
A sequence of nine integers of 1 to 9.


Note that the nine integers have NO need to be different.

Output

The sum of the integers being visited.

Remember to print a ' ' at the end of the sum.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10151 - Lab04   

Description

As described in Wikipedia, Pascal's triangle is a triangular array of the binomial coefficients. The element k on row n of Pascal’s triangle can be calculated by the following relation:
C(n, 1) = 1, for n = 1, 2, …
C(n, n) = 1, for n = 1, 2, …
C(n, k) = C(n-1, k-1) + C(n-1, k),  for k = 2, 3, … and for n = 2, 3, …

Given a sequence of numbers, please print the corresponding rows of the Pascal’s triangle.
Use '%10d' to print each element. Print a newline ' ' at the end of each row.

Hint:
You should first create a Pascal’s triangle from row 1 to row 30.

Input

A sequence of positive integers, and each of them is smaller than 31.

Output

Print the corresponding rows of the Pascal’s triangle.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10186 - Lab05   

Description

Complete the following program of car and jewels.
map[][] is a two-dimensional array representing the content of the map.
map_reset() is to clear the map and reset the boundary.
map_show() is to display the map.
blocks[][] is also a two-dimensional array that indicating the locations of brick walls.
We may use blocks_read() to read the locations of brick walls from the input, and then use blocks_put_on_map() to place the bricks at the indicated locations in the map.
Note that the car will stop moving if it runs into a wall.
jewels[][] is a two-dimensional array recording the locations of jewels.
We use jewels_read() to read the jewel locations from the input, and then use jewels_put_on_map() to place the jewels at the indicated locations in the map.
Note that if the car’s location overlaps the locations of some jewels, those jewels will be picked up into the car.
The car’s shape is also represented by a two-dimensional array. The two symbols @ @ denoting the head lights, so we can decide which direction the car is heading by the two symbols @ @. The starting position of the car is row 3 column 4 (the center of the car). We use two variables car_row and car_col to store the car’s current position. The variable car_direction denotes the car’s direction. The variable car_earnings denotes the number of picked jewels in the car.
Note that we can use 0, 1, 2, 3 to represent the car’s direction as right, down, left, and up. That is, if the value of car_direction is 2, it means that the car is moving toward the left. The initial value of car_direction is 3 (heading upward).

Our task is to complete the two functions car_rotate270() and car_move()
The function car_rotate270() is to rotate the car (2D array) clockwise by 270 degrees and update the value of car_direction.
The function car_move() is to move the car forward by one step according to the current direction of the car. We need to check if the car is going to hit the wall before we let it move forward. We need to pick up the jewel underneath the car before we move. Once the jewels are picked up, they will not be available on the map anymore.

The input contains two types of commands, corresponding to two actions.
'R' represents rotating clockwise by 270 degrees
'F' represents moving forward by one step.
We need to show the final state of the car after carrying out all of commands. The output should include car_earnings, car_row, car_col, and car_direction. Note that the size of the map is fixed to 10.

The following is an example of a possible game state at some moment.
HHHHHHHHHH
H........H
H.#....#.H
H....@[email protected]
H.$..OOO.H
H....OOO.H
H..$.....H
H.#....#.H
H........H
HHHHHHHHHH

The symbol 'H' denotes a wall at the map border, the symbol '#' denotes a brick wall, the symbol '$' denotes a jewel, and the car is
@O@
OOO
OOO

In this case car_row is 4, car_col is 6 and car_direction is 3.

Note that when you test your program on your pc, you should press control+Z to send an EOF to the program and thus exit the main loop.

The code template:
 

#include 
#define MAP_SIZE 10
#define CAR_SIZE 3

int map[MAP_SIZE][MAP_SIZE];
void map_reset(void);
void map_show(void);

int blocks[MAP_SIZE][MAP_SIZE];
void blocks_read(void);
void blocks_put_on_map(void);
int jewels[MAP_SIZE][MAP_SIZE];
void jewels_read(void);
void jewels_put_on_map(void);

int car[CAR_SIZE][CAR_SIZE] = {{'@', 'O', '@'}, {'O', 'O', 'O'}, {'O', 'O', 'O'}};
int car_row = 3, car_col = 4;
int car_direction = 3;
int car_earnings = 0;
void car_rotate270(void);
void car_put_on_map(void);
void car_move(void);

int main(void)
{
    int ch;
    char dirs[] = "RDLU";

    jewels_read();
    blocks_read();
    

    while ((ch=getchar()) != EOF) {
        if (ch=='R') {
            car_rotate270();
        }
        if (ch=='F') {
            car_move();
        }

        map_reset();
        jewels_put_on_map();
        blocks_put_on_map();
        car_put_on_map();
        /* You may call map_show() to print the current state.
        Be sure to remove it before you submit the code */
        /*map_show();*/
    }


    printf("%d\n", car_earnings);
    printf("%d %d\n", car_row, car_col);
    printf("%c\n", dirs[car_direction]);

    return 0;
}

void blocks_read(void)
{
    int n, i;
    int row, col;
    scanf("%d", &n);
    for (i=0; i
  

Input

The input contains several lines. The first line contains an integer N indicating the number of jewels. The next N lines are the locations of the N jewels. The next line contains an integer M indicating the number of brick walls. The next M lines are the locations of the M brick walls. The last line of the input contains a sequence of commands for the car’s actions.
Note that the jewels may appear underneath the car in the beginning and should be picked up.

Output

The output contains three lines displayed using

printf("%d\n", car_earnings);
printf("%d %d\n", car_row, car_col);
printf("%c\n", dirs[car_direction]);

Sample Input  Download

Sample Output  Download

Tags




Discuss




10236 - Lab06   

Description

Given a number N, we can create an N by N matrix as below:
  1   2   3   4   5 
 16  17  18  19   6 
 15  24  25  20   7 
 14  23  22  21   8 
 13  12  11  10   9 

In this case, N = 5, and the elements are in order from 1 to N2 as a clockwise spiral pattern.
Note that we always start from the upper left corner.

Now we have a sequence of numbers, please print the corresponding matrices.

Input

A sequence of numbers, each number N indicates the size of matrix. (1 <= N <= 20)
The input is terminated by a newline '\n'.

Output

The matrices corresponding to the input.
Use "%3d " to printf each element. Print a newline '\n' at the end of each row. 

Sample Input  Download

Sample Output  Download

Tags




Discuss




10267 - Lab07   

Description

Suppose that you have a lot of coins and bills of different values, but the numbers of them are limited. Given an amount of money, you need to find the best way to get the change. By ‘best’, we mean that we the total number of coins should be as small as possible.

For example, assume that we have 10 coins in $1, 10 coins in $5, and 10 bills in $10.To get the change for $17, we need 2 coins of $1, 1 coin of $5, and 1 bill of $10.
Another example: assume that we have 10 coins in $1, 10 coins in $5, 10 bills in $10 and zero bills in $50. To get the change for $57, we need 5 bills of $10, 1 coins of $5, and 2 coins of $1.

Note that you can always find at least one way to get the change.

The following is an excerpt of incomplete code:

#include 
#define MAXNV 5

int DONE = 0;
int values[MAXNV];
int limits[MAXNV];
int numbers[MAXNV];
void show(int nv);
void change(int amount, int cur, int nv);

int main(void)
{
    int nv, i;
    int money;
    scanf("%d", &nv);
    for (i=0; i
  

Input

The input contains three lines. The first line contains an integer N (0The third line contains N integers indicating the limited numbers of the coins and bills. The final line contains the amount of money for change.

Output

The result can be displayed by calling the function show()
Only the best way for change should be displayed.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10294 - Lab08   

Description

The input is a sequence of positive fractions, e.g., 1/2, 2/3, 3/4. To get the output, let the first fraction minus the sum of the others, which is -11/12 in this case.
Note that the answer should be expressed in simplest terms, for example,  the output of 8/4 minus 3/2 should be displayed as 1/2 not 2/4.
If the answer is an integer then the denominator should be 1, for example, the output of 3/2 minus 1/2 should be 1/1.
Furthermore, if the answer is negative, add a symbol '-' at the beginning of the output.
Note that the input may not be simple fractions.

hints:
1. Calculate the least common multiple of the denominators.
2. You may implement the following two functions for computing the greatest common divisor and the least common multiple:

int gcd(int a, int b);
int lcm(int a, int b);

Input

The first line is an integer N (0 The next N lines contain the N positive fractional numbers, represented as a pair of numerator and denominator.  The numerators and the denominators are two-digit numbers (smaller than 100).

Output

The output is a pair of numerator and denominator, ended with a newline character.

Sample Input  Download

Sample Output  Download

Tags




Discuss




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




10328 - Lab10   

Description

Suppose we have 100 variables (variable 1 ~ variable 100) and a series of equivalence relations.
For instance, 2 3 represents that variable 2 and 3 are equivalent.
Given a query, your job is to count how many variables equal to the queried variable (except for the queried variable)

Input

M (the count of equivalence relations)
Relation 1
Relation 2

Relation M
P (the count of queries)
Query 1
Query 2

Query P

Output

For each query, output how many variables equal to the queried variable.
Print a newline '\n' at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10364 - Lab11   

Description

Given a sequence of  2-digit numbers, use ‘qsort’ to sort the numbers in the following rule:
1. First, sort the numbers by tens digit in increasing order. E.g., 10 is prior to 20.
2. If numbers have the same tens digit, sort them by units digit in decreasing order. E.g., 39 is prior to 38.

Hint:

#include 
#include 
#define SIZE 10
#define LENGTH 2

int comp_func(const void *a, const void *b)
{
    /* your code here */
}

int main()
{
    int i, N;
    int num[SIZE][LENGTH];
    int *ptr[SIZE];
    char str[LENGTH+1];

    scanf("%d", &N);
    for (i=0; i
  

Input

N
Number1
Number2
...
NumberN

Output

Print the sorted numbers line by line. Each line contains one number and ends with a newline character.

Sample Input  Download

Sample Output  Download

Tags




Discuss