628 - I2P2014_Exercise_1 Scoreboard

Time

2014/09/18 00:00:00 2014/09/18 00:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10158 2's complement
10159 GCD and LCM
10160 typewriter
10162 Matrix multiplication
10168 Shooting star
10169 Compounding
10170 Star

10158 - 2's complement   

Description

 Transform the input x, into y bits 2’s complement.

The procedure of transforming an positive integer into its two’s complement is showed as follow:

Step1: transform the input into y-bits binary representation.

Step2: toggle each bits of the binary representation.

Step3: add 1 to the binary representation.

For example,

Input: 28 33

Step1: transform integer into binary representation, 28 -> 000000000000000000000000000011100

Step2: toggle each bits -> 111111111111111111111111111100011

Step3: add 1 -> 1111111111111111111111100100

So, the two’s complement representation of 28 is 111111111111111111111111111100100.

Example2:

Input: 10 34

Step1: transform integer into binary representation, 10 -> 0000000000000000000000000000001010

Step2: toggle each bits -> 1111111111111111111111111111110101

Step3: add 1 -> 1111111111111111111111111111110110

So, the two’s complement representation of 10 is 1111111111111111111111111111110110.

 

Don't forget to print a newline in the end.

Input

 Two positive integer x and y, where 0 < x < 2^32, and 32 < y < 100

Output

 Two’s complement of x

Sample Input  Download

Sample Output  Download

Tags




Discuss




10159 - GCD and LCM   

Description

Given two positive integer x and y, calculate the GCD (greatest common divisor) and LCM (least common multiple) of x and y.

 


Hint:

#include

int main()
{
        int x, y;
        scanf("%d %d", &x, &y);
        int xcp, ycp;
        int gcd;


        // x is not necessarily bigger than y
        xcp = x;
        ycp = y;
        while(xcp > 0 && ycp > 0){
                 /* calculate the gcd */
                 /* add your code here */
        }

        /* determine which one is gcd */
        /* add your code here */

        printf("GCD: %d\n", gcd);
        printf("LCM: %d\n", x*y/gcd);

        return 0;
}

 

Input

 Two positive integer x and y, where 0 < x,y < 10000.

Output

 GCD and LCM of x and y.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10160 - typewriter   

Description

Long time ago, a writer should use a typewriter to print the letters on the paper, rather than on the screen. However, if any key on the typewriter is broken, the work will be suspended till the key is repaired. Your work is to design a program that can check which letter is used most and which letter is used least. Then, you can prepare a new key in advance to repair the broken one. In addition, we do not need to prepare the key for the letter that appears least because many other keys will break before it.

Input

A random string containing only letters (without digits).

They will be either upper case or lower case.

The length of input string will less than 50.

Output

Show the letter that appears most and least (in lower case) with how many times they appear.

Please follow the format of sample output.

If more than one letter counts the same times, print the previous one of the ahphabetical sequence.

Upper case or lower case of the same letter will be regarded as the same letter.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10162 - Matrix multiplication   

Description

Given two matrices A and B of size m x n and n x p, calculate C = A x B.

The matrix multiplication is defined as follows:

         n
Cij Σ  Aik x Bkj
       k=1

Input

m n
A11 A12  ... A1n
...
Am1 Am2  ... Amn
n p
B11 B12 ... B1p
...
Bn1 Bn2 ... Bnp

Each entry is a positive integer no more than 20, and 0 < m, n, p < 10.

Output

C11 C12 ... C1p
...
Cm1 Cm2 ... Cmp

Print each entry with "%d " (a number followed by a whitespace)
Note that there is a newline character at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10168 - Shooting star   

Description

Given the boundaries, the start point of a shooting object, and the direction of shooting, you have to show the route of the shooting object.

If the object hit the boundary, it would reflect with 45 degree.

You are asked to use 2-D arries to solve this problem.

Input

The first line has three numbers, C, F(5<=C, F<=20) and H(2<=H<=20), which respectively means the length of the ceiling, the length of the floor, and the height between the ceilings and floors.

The second line has a number S(1<=S<=H), which means the start point of shooting object. It's noted that the location below the ceiling is 1, and the location below that is 2, and so on.

The third line has a character 'u' or 'd'. If you get ‘u’, the initial direction of shooting is upper-right in 45 degree. If you get 'd', it means lower-right in 45 degree.

Output

Draw the map and the route of the shooting object.
The route of shooting object is marked as ‘*’, which appears until the object is out of boundaries.

You need to use a (H+2)*(max{C, F, the horizontal length of route of shooting}) array to print out the result

(for example, the sample output is printed from a 5*10 array)

Remember there is '\n' in the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10169 - Compounding   

Description

In the beginning of this year, Wooder creates a bank account which pays 0.6% interest per year, compounded yearly. Then, Wooder may deposit or withdraw some amount of money in the beginning of each of the following years. You are asked to help calculate the amount of money in Wooder’s bank account.

Consider the following example:


  • In the beginning of year 1, the account balance is 500.00.
  • In the beginning of year 2, the account balance is (500*1.006) + 100=603.00.
  • In the beginning of year 4, the account balance is (603*1.0062) - 450=160.26.
  • To accumulate Wooder’s account in the beginning of year 7, we can report that the total amount of money is 160.26*1.0063=163.16.l  

 

Input

The input contains several lines. Each line contains three elements, which are separated by blanks, describing the bank transaction at a specific year:

  • The first element indicates the year.
  • The second element indicates deposit (D), withdraw (W) or accumulate the account (A).
  • The third element indicates the amount of money when depositing or withdrawing.

Note that 0 < year < 100, and 0 <= money <= 1000.

When your program reads in an “accumulate” (A) instruction, it will output the balance of Wooder’s bank account at the beginning of the indicated year. Then your program is terminated

Output

The amount of money in Wooder’s bank account.
The answer should be expressed as a floating point number with precision to the second decimal place. Note that you need to print a ' \n' at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10170 - Star   

Description

Given two integers N and M, and a starting point with coordinates (x, y). You are asked to create an N-by-M matrix as follows.

  • Find the matrix element for the starting point, that is, with row index x and column index y, and set this element’s value as 'S'.
  • For a matrix element other than the starting point, if its row index is x or its column index is y, then set its value as '+'.
  • If a matrix element is on the diagonal line of the starting point, then set its value as '*'.
  • For all other matrix elements, set their values as '-'. 

Input

Four integers separated by blanks. The first integer (N) represents that the matrix has N rows. The second integer (M) represents that the matrix has M columns. The third integer (X) and the fourth integer (Y) represent the coordinates of the starting point.

( 1 <=N,M<= 15, 0 <= X < N, 0 <= Y < M )

 

Note that (0, 0) is on the most top-left of the matrix.

Output

The N-by-M matrix. Print the elements of the matrix using the format "%c". Each row is ended with a newline character '\n'.

Sample Input  Download

Sample Output  Download

Tags




Discuss