608 - CS135502_I2P2014_LAB Scoreboard

Time

2014/01/08 13:40:00 2014/01/08 15:10:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10000 hello world
10061 lab02
10065 lab01
10100 Bell Triangle
10101 lab04
10117 lab03
10152 wave
10171 Chinese Words
10185 lab05
10219 lab06
10266 lab08
10270 lab07-1
10271 lab07-2
10310 Math Loop
10311 Polynomial
10314 lab09-1
10315 lab09-2
10334 lab10
10336 Police
10368 mid2補考_problem1
10369 sosort
10371 lab11

10000 - hello world   

Description

 print "hello world"

Input

(no input)

Output

 print out hello world on screen.

Sample Input  Download

Sample Output  Download

Tags

hi #include <stdio.h> #include<stdio.h> in hello world \n HAHA



Discuss




10061 - lab02   

Description

The input is a four-digit positive integer x that consists of digits 1-9 except 0. Let y be the number with the first two digits and the rest of x swapped. For example, if x is 9527, then y is 2795. Now, calculate z, which is the square of y, and encode z by the following mapping:
1->’A’, 2->’B’, 3->’C’, …, 9->’I’, 0->’J’
You should pad 0 on the left of z to make z an eight-digit number before encoding.
That is, since y is 2795 and its square z is 7812025, the padded version of z is 07812025, and so your answer should be JGHABJBE.
 

Input

A four-digit positive integer consisting of 1-9 except 0.

Output

The encoded z. Note that you do not need to print ‘ ’ at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10065 - lab01   

Description

An arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15 … is an arithmetic sequence with common difference of 2.

Here, you are given an arithmetic sequence, where the initial term is ‘a’, the total number of terms in this sequence is ‘n’, and the common difference of successive terms is ‘d’. Then, in this sequence: what is the value of the nth term, and what is the sum of all the terms?

Input

Three integers separated by blanks. The first integer (a) is the initial term, where -1000=0 and n<1000. The third integer (d) is the common difference, where -1000

Output

Two values separated by a blank. The first value is the nth term of the sequence, and the second value is the sum of the sequence. Note that you do not need to print '\n' at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10100 - Bell Triangle   

Description

As described in Wikipedia,
Bell triangle is a triangle of numbers analogous to Pascal's triangle, whose values count partitions of a set in which a given element is the largest singleton.

Construction of the Bell triangle:

Bell(1,1) = 1
Bell(n,1) = Bell(n-1,n-1), for n = 2, 3, 4, ...
Bell(n,k) = Bell(n-1,k-1) + Bell(n,k-1), for n = 2, 3, ... and k = 2, 3, ...

Or you can do step by step as follow:



Given a postive integer N,
display the Bell’s triangle from row 1 to row N.
Use '%11d' to print each row element and print a newline at the end of each row.

Input

Given a postive number N and the range of N is 1 ≦ N ≦ 15.

Output

Print the Bell triangle from row 1 to row N,
and all elements of Bell triangle are smaller than 231-1.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10101 - lab04   

Description

Given a N x N board and a coordinate of point S, (x, y), you need to compute the shortest distance between each grid on the board and the point S.

The shortest distance only counts horizontal and vertical steps. The distance between one grid and the neighbor one is 1.

 

Input

Each testcase has two lines. The first line has N(3<=N<=7), which means the size of the board. The total number of grids on the board would be N x N.

The second line has two numbers, x and y(1<=x, y<=N), which mean the coordinate of the point S. x is the row index, and y is column index.

Note that (1, 1) is on the upper-left corner of the board.

Output

Print out the board, where the element of each grid is the shortest distance from the point S.

The element of point S is 0.

Note that you have to use "%3d" to print the output, and there is a '\n' at the last line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10117 - lab03   

Description

The input contains fifteen different integer numbers, which are 1 to 15 in some random order. Consider, for example, a sequence: 4 3 7 9 15 14 2 1 5 8 11 6 10 12 13. In this sequence, starting 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 5. We repeat this process until we go to a place that has already been visited. In this example, we will stop at the 8th place and get the number 1, because we have found a circle. Therefore, along the way we pick eight numbers, 4 9 5 15 13 10 8 1.

In this problem, you will be given such a sequence of fifteen numbers. Follow the above visiting rule, please
1. get the corresponding sequence of numbers;
2. calculate their sum;
3. convert their decimal representation into hexadecimal representation as the output. For example, the sum of the above instance is 65. Their hexadecimal representation is 41.

Note that we always start from the first place.
Note that, for example, if the sum of these numbers is 95, your hexadecimal number should be 5F. 


Hint:

decimal hexadecimal decimal hexadecimal
0 0 8 8
1 1 9 9
2 2 10 A
3 3 11 B
4 4 12 C
5 5 13 D
6 6 14 E
7 7 15 F

 

Input

A random sequence of the fifteen different numbers of 1 to 15, which are separated by blanks.

Output

The hexadecimal representation of the sum of the numbers being visited.
Remember to print a ' ' at the end of the answer.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10152 - wave   

Description

Give a character C , a length L and number N.

Print out a wave is build by the character C and maximum length L.
Total print N wave.

Input

Three input, C, L, N.
C means character.
L means length, 1
N means number, 1

Output

Print out a wave is build by the character C and maximum length L N times.
Note: There is no newline at last line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10171 - Chinese Words   

Description

In traditional chinese, people write words from right top to left down.

Now  you have a grid paper which contains N words. N will not bigger than 4096.

The size of the grid paper is H * W (height * width). The size of H and W are between 1 to 64.

Each grid only write a character.

You have to implement two parts :

  1. You have to rewrite an article from right top to left down.
  2. If the word is a space, namely ' ',  then you have to skip it.

[Note]The blanks at the left down should be filled with ' '.

Hint:

Input

There are 3 input.

1. The number of characters (N) in the article. 0<=N<=4096

2. The size of the grid paper : H (height) and W (width).  1<=H<=64, 1<=W<=64

3. The contents of the article

Output

Rewrite the article which is height H and width W from right top to left down.

There is a newline at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10185 - lab05   

Description

Suppose that we have a deck of 52 cards (poker), the number is mapping A to 1, J to 11, Q to 12, and K to 13. Suppose that you are given 5 cards from the deck, and you should print the corresponding category to these five cards.
Note that you do not consider the colors.
Category:
1. Four of a kind (ex: 10 10 10 10 3)
2. Full house (ex: 9 9 9 2 2)
3. Two pair (ex: 5 5 6 6 8)
4. Nothing (ex: 8 7 1 9 5、4 1 8 8 8、2 3 4 5 6、7 7 2 8 6)

For example, you are giving the five cards are 8 3 8 3 8. Corresponding to the category is Full house, and you should print Full house as your output.

Hint:

#include 
int main(void){

	int card[5];		//the cards’ numbers of input
	int count[14] = {0};	//the amount of each number of the cards
	int twocount=0;		//the count of pair
	int threecount=0;	//the count of triple
	int fourcount=0;	//the count of quadruple
    
	/*  get the input and count the amount of each number of the input  */
   
	/*  consider the category and print the output  */

}

Input

You are given the five cards and the number of the cards is from 1 to 13, which are separated by blanks.

Output

The corresponding category to these five cards.
Remember to print a '\n' at the end of the answer.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10219 - lab06   

Description

Calculate the addition of big numbers.

 

hint : the ASCII code of digits

character

ASCII code

(in decimal)

0 048
1 049
2 050
3 051
4 052
5 053
6 054
7 055
8 056
9 057

 

Input

The form of input is {A + B}.

There is a blank space between A and '+' as well as between '+' and B.

A new line character at the end of input.

0<=A, B<=10100

Output

The result of calculation.

No new line character at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10266 - lab08   

Description

Given two positive integer sequences {ai} and {bj} (0 < ai, bj < 100), calculate the continued fraction generated by those two sequences.
The continued fraction x is defined as:




For example, if the sequences {ai} is {2, 7, 3} and {bj} is {3, 2, 2}, then the answer should be 3/(2 + 7/(2 + 2/(3 + 1))) = 5/8

Note that your answer should be expressed in simplest terms. That is, 2/4 should be represented as 1/2. If the answer is an integer then the denominator should be showed as 1. For example, 3 should be represented as 3/1.

Hint:
You may use the following incomplete code to solve the problem:

#include <stdio.h>

int a[10], b[10];

int gcd(int a, int b)
{
    /* your code here */
}

int main(void)
{
    int i, n;
    int de, nu;
    int tmp, g;
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d%d", &a[i], &b[i]);
    }

    nu = 1;
    de = 1;
    for (i = 0; i < n; i++) {
        /* your code here */
    }
    printf("%d %d\n", nu, de);

    return 0;
}

Input

The length of the sequence (0 < n < 10).
a1 b1
a2 b2

an bn
 

Output

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

Sample Input  Download

Sample Output  Download

Tags




Discuss




10270 - lab07-1   

Description

Suppose that you have an infinite number of containers with different sizes, already filled with water. Given another empty container with size N liters, you need to find the best way to fill this N-liter empty container using the provided smaller containers. By ‘best’, we mean that the total number of used containers should be as small as possible. For example, assume that we have containers in 1, 5, and 10 liters. To get the 17 liters of water, we need 2 containers of 1 liter, 1 container of 5 liters, and 1 container of 10 liters. Another example: assume that we have containers in 1, 5, 10 and 50 liters. To get the 57 liters of water, we need 1 container of 50 liters, 1 container of 5 liters, and 2 containers of 1 liter. Note that, to avoid water wastage, if you choose to use a container, all the water in this container should be poured.

The following is an excerpt of incomplete code:

#include <stdio.h>
#define MAXNV 5
int DONE = 0;
int liters[MAXNV];
int numbers[MAXNV];
void show(int nv);
void filling(int amount, int cur, int nv);
int j=0;
int water;
int min=100;
int min_numbers[MAXNV]={0};
int main(void)
{
    int nv, i;

    scanf("%d", &nv);
    for (i=0; i<nv; i++) {
        scanf("%d", &liters[i]);
    }
    scanf("%d", &water);
    filling(water, 0, nv);

    for(i=0;i<nv;i++)
        numbers[i]=min_numbers[i];
    show(nv);
    return 0;
}

void show(int nv)
{
    int i;
    printf("(%d", numbers[0]);
    for (i=1; i<nv; i++) {
        printf(",%d", numbers[i]);
    }
    printf(")\n");
}

void filling(int amount, int cur, int nv)
{
    int i,j,count_numbers=0;

    if(cur<nv){
        if(amount==0){
            for(i=0;i<nv;i++)
                count_numbers=count_numbers+numbers[i];

            if(count_numbers<min){
                min=count_numbers;
                for(i=0;i<nv;i++)
                    min_numbers[i]=numbers[i];
            }
        }
        else if(amount>=liters[cur]){
            /*your code*/
        }
        else{
            /*your code*/
        }
    }
}

Input

The input contains three lines. The first line contains an integer N (0

Output

The result can be displayed by calling the function show().
Only the best way to fill the empty container should be displayed.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10271 - lab07-2   

Description

Given a set of n≥1 elements, the problem is to print all possible permutations of this set. For example, if the set is (1,2,3), then the set of permutations is {(1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1)}.


Looking at the case of four elements (1,2,3,4). The answer can be constructed by writing
a. ‘1’ followed by all the permutations of (2,3,4)
b. ‘2’ followed by all the permutations of (1,3,4)
c. ‘3’ followed by all the permutations of (1,2,4)
d. ‘4’ followed by all the permutations of (1,2,3)


A recursive method to implement the above idea is as follows:
Consider the case of (1,2,3,4), that is, n=4.
1. Place the set elements in a global array, and set the position index “k” as 0.
2. Use a for-loop to “swap” (or exchange) the 1st element with the 1st element, the 2nd element, the 3rd element, and the 4th element, respectively.
    In each loop-iteration:
      i. increment the position index “k” by 1 (for considering only the remaining elements in the following recursive call);
     ii. use the updated k to recursively call your permutation function;
    iii. note that because you use a global array, remember to swap back the two elements after the iteration.
3. In a recursive-call path, when k reaches n, it means that you get a possible permutation.

You can use the following incomplete code to solve this problem.

#include 

void Show(int n);
void Swap(int k, int i);
void Perm(int k, int n);
char list[9]={'1','2','3','4','5','6','7','8','9'};

int main(void)
{
    int num;

    scanf("%d",&num);
    Perm(0,num);
    return 0;
}

void Show(int n)
{
    int i;
    printf("(%c", list[0]);
    for (i=1; i
  

Input

The decimal number n that represents the number of elements in the set.
(1≤n≤9)

Output

In the output you should print all the permutations.
Be sure to add a newline character '\n' at the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10310 - Math Loop   

Description

Observe the following instructions to solve a simple problem.

1.          Input a sequence A, and then arrange the sequence number from large to small in order to get the new sequence B.

2.          Do in the same way by step 1, but this time arrange the sequence A from small to large in order to get another sequence C.

3.          Calculate the difference of B and C, that is, B-C.

4.          Use B-C in step 3 as a new sequence A and repeat the above steps 1 to 3.

5.          The repetitions end when a difference has been observed in the previous operations.

6.          Finally you need to print the times that step 3 is executed.

 

Note: the input won’t be 0.

 

Example:

For the sequence A=3412, the sequence B from large to small is 4321. Besides, the sequence C from small to large is 1234.
Then follow the above instructions, we have 4321 - 1234 = 3087, 8730 - 378 = 8352, 8532 - 2358 = 6174, 7641 - 1467 = 6174.
In this case, you should print the number 4.

For another sequence A=12345, the sequence B from large to small is 54321. Besides, the sequence C from small to large is 12345. 
Then follow the above instructions, we have 54321 - 12345 = 41976, 97641 - 14679 = 82962, 98622 - 22689 = 75933, 97533 - 33579 = 63954, 96543 - 34569 = 61974, 97641 - 14769 = 82962.
In this case, you should print the number 6.

 

Input

The input sequence contains no more than six digits.

 

Output

The times that step 3 is executed.

Note that there is a newline character at the end of the output.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss




10311 - Polynomial   

Description

There are two polynomial equations f(x) and g(x).

 f(x)=(am xm+a(m-1) x(m-1)+⋯+a1 x1+a0 x0)n

g(x)=cp xp+c(p-1) x(p-1)+⋯+c1 x1+c0 x0

,where n,m,p∈N,0≤p<100.

In this problem, we define g(x) as the expand form of f(x). For example, if f(x)=(x+3)2, then g(x)= x2+6x+9.

 

Note that all the coefficients are integers.

Input

m

am a(m-1)  … a1 a0 

n

Note that the coefficients are separated by a blank.

 

Output

cp c(p-1)  … c1 c0

Note that you need to use “%5d” to print answer and there is a new line at the end.  

 

Sample Input  Download

Sample Output  Download

Tags




Discuss




10314 - lab09-1   

Description

Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. Note that the order of the bubble sort is ascending.

Step-by-step example
Let us take the array of numbers "5 1 4 2 8", and sort the array from the lowest number to the greatest number using the bubble sort. In each step, the elements written in bold are being compared. There are some passes as follows.

( 5 1 4 2 8 ) → ( 1 5 4 2 8 ). Here, the algorithm compares the first two elements, and swaps them since 5 > 1.
( 1 5 4 2 8 ) → ( 1 4 5 2 8 ). Swap since 5 > 4
( 1 4 5 2 8 ) → ( 1 4 2 5 8 ). Swap since 5 > 2
( 1 4 2 5 8 ) → ( 1 4 2 5 8 ). Now, since the two elements are already in order (8 > 5), the algorithm does not swap them.
Therefore, we note that after 4 comparisons, the largest number 8 can be determined.


( 1 4 2 5 8 ) → ( 1 4 2 5 8 ).
( 1 4 2 5 8 ) → ( 1 2 4 5 8 ). Swap since 4 > 2
( 1 2 4 5 8 ) → ( 1 2 4 5 8 ).
Therefore, after 3 comparisons, the second largest number 5 can be determined.
.
.
.
<(5-1=4)-th Pass>
After this pass, the smallest number 1 can then be determined.


You need to write double for-loops (nested for-loops):
1. The outer for-loop runs through the required n-1 passes.
2. The inner for-loop carries out the swaps in each pass.

The following is an excerpt of incomplete code:

#include 
  

Input

The input contains two lines.
The first line contains an integer N (0 The second line contains a list of the values of the N elements, which are separated by blanks.
 

Output

In the output you should print the sorted list.
Be sure to add a newline character at the end.
 

Sample Input  Download

Sample Output  Download

Tags




Discuss




10315 - lab09-2   

Description

Find the median from an unsorted list.
Note that if a < b < c, then the median of the list {a, b, c} is b, and, if a < b < c < d, then the median of the list {a, b, c, d} is the mean of b and c; i.e., it is (b + c)/2.


You can use the bubble sort first and then find the median from the sorted list.
 

Input

The input contains two lines.
The first line contains an integer N (0 The second line contains a list of the values of the N elements, which are separated by blanks.
 

Output

Print the median of the list of the input. The answer should be expressed as a floating point number with precision to the first decimal place. For example, 4.0 or 6.5.
Be sure to add a newline character at the end.
 

Sample Input  Download

Sample Output  Download

Tags




Discuss




10334 - lab10   

Description

This problem deals with deposit (D) and withdrawal (W) of bank accounts. We have known that several users may share a single account. You will be indicated if a user shares a same account with another user. Then you will be asked to perform several account deposit or withdrawal, and calculate the average account balance.

 

For instance, an input line 1 2 represents that users 1 and 2 share with the same account. Users 1 and 2 can deposit or withdraw the money in their shared account. If the account has 0 dollars originally, an input line 1 D 60 represents that user 1 deposits 60 dollars and 2 W 20 represents that user 2 withdraws 20 dollars to/from their shared account. In the end, there are 40 dollars and 2 users with the same account. Thus, the average money of their account is 40/2=20.00 dollars.

 

Note:

(1)   Suppose we have 100 members at most.

(2)   Each account has 0 dollars in the beginning.

(3)   For a withdrawal operation, if the account balance is smaller than the amount of money to be withdrawn, this operation should be ignored.

Input

M

Users a1 and b1 share a same account

Users a2 and b2 share a same account

Users aM and bM share a same account

N

Account operation 1 (User / Deposit (D) or Withdraw (W) / Money)

Account operation 2 (User / Deposit (D) or Withdraw (W) / Money)

Account operation N (User / Deposit (D) or Withdraw (W) / Money)

P

User_ID1 User_ID2 … User_IDP

Output

Calculate the corresponding average account balance of the asked P users (User_ID1, User_ID2, … , User_IDP).

Each answer is printed using the format “%.2f\n”.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10336 - Police   

Description

The scenario: You are a police officer and there are some bad guys hiding behind the blocks.

Given a map represented as a two-dimensional array, the bad guys are hiding at the top row of the map. From the second row to the bottom, there are several blocks. You are at the bottom row of the map. You have to use your gun to destroy the blocks in front of you so that you can defeat the bad guys.

Every bad guy or block has a vitality level. When you fire at a block, the vitality level of it is decreased by 1; if the vitality level of a block becomes 0, it is destroyed. Similarly, when you fire at a bad guy, his vitality level is decreased by 1. If his vitality level is 0, he is defeated.

The following image shows the situation at certain moment.


Input

The first line contains two numbers I and J, which denote the size of the place (I for rows and J for columns, 3 <= I, J <= 5). 

The next line contains J numbers, which indicate the vitality levels of the bad guys at the corresponding columns. If the number is 0, it means that at that column there is no bad guy.

The following I-1 lines indicate the existence of blocks from row 2 to row I. Each line contains J numbers corresponding to the J columns. If the number is larger than 0, it means that there is a block at that column. Note that there is no block at row I, which means that all the J numbers for row I are 0.

The value of vitality level is between 1 and 9.

The final line gives a sequence of instructions telling that, at which column you should fire. The end of the instructions is marked as 'e'.

For example, if the instructions are "1 2 1 e", you should fire at the first column, then the second column, and then the first column again. The length of sequence is less than 10.

Output

Show the final configuration of the map after the instructions are done, using the same form as the input.

That means every integer in the map is printed by "%2d". Remember to print a newline character '\n' at the end of each row.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10368 - mid2補考_problem1   

Description

The input contains two polynomials f(x) and g(x).
f(x) = amxm + a(m-1)x(m-1) + ⋯ + a1x1 + a0x0
g(x) = bnxn + b(n-1)x(n-1) + ⋯ + b1x1 + b0x0

where m,n∈N, 0≤m,n≤10.

Compute h(x) = f(x)g(x).
Note that all the coefficients are integers.

Input

m
am a(m-1)  … a1 a0
n
bn b(n-1)  … b1 b0


Note that the coefficients are separated by a blank.

Output

The coefficients of h(x) in descending power order.
Use "%d " to print each coefficient and there is a newline at the end.

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




10371 - lab11   

Description

Given a list of English names, use ‘qsort’ to sort the names in lexicographic order. The number of names is less than or equal to 10, and each length of the name is no more than 5.

The detailed rules of sorting are:
1. Sort the strings in alphabetical order. E.g. “abc” is prior to “abd”.
2. The string with smaller length has top priority. E.g. “xyz” is prior to “ABCD”.
3. The uppercase alphabet is prior to lowercase alphabet. E.g. “AA” is prior to “aA”.

You may use the following piece of code:
 

#include 
#include 
#include 

#define SIZE 10
#define LENGTH 6

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

int main()
{

    char strs[SIZE][LENGTH] = {0};
    char *ptrs[SIZE];
    int i, N;

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

Input

Number of names
Name 1
Name 2
Name 3

Output

Print the sorted names line by line. Each line contains one name and ends with a newline character.

Sample Input  Download

Sample Output  Download

Tags




Discuss