1515 - I2P (I) 2018_Yang_hw2 Scoreboard

Time

2018/10/01 17:00:00 2018/10/15 15:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11127 Binary representation&sum
11561 Point distance
12009 Caesar salad
12013 multiplication

11127 - Binary representation&sum   

Description

Problem Description

Given a positive integer N, transform it to its unsigned binary representation (e.g. 10 => 1010). Your program needs to output the binary representation of N+1 and the number of carries during the addition in binary representation.

 

For example, if the input is 11 (in decimal), your program needs to output 1100, because it is the binary representation of 11+1=12. Also your program needs to output 2, because during the binary addition of 11+1, there are two carries generated.

 

     1011 (11 in binary)

+   0001 (1 in binary)

---------------------------------

     1100 (12 in binary)

Input

The input consist of an integer N (0 <= N <= 1024)

Output

The binary representation of N+1 and the number of carries during the binary addition of N+1. Those two numbers are separated by a space. Note that you do not need to print ‘\n’ at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11561 - Point distance   

Description

The purpose of programming is to solve complicated problems that humans are not able to solve quickly.

In the xy-coordinate system, there are a given line and a given point on the plane. The task is to print out the square of the shortest distance from the point to the line.

 

 

Input

Output

Please output the square of the distance from the point P to the line L with a new line. Note that the answer should be rounded to the second decimal place.

You can use printf(“%.2f\n", your_ans) to print out your answer. Remember that your_ans has to be in double type.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss




12009 - Caesar salad   

Description

Caesar wants to eat salad, but nobody sells salad within his country. Thus, he decides to write a letter to the businessmen outside his country. But to secure his message, he has to encrypt the content of his letter.

The encrypt rule is as follow: For each English character inside his letter, shift it with a fixed number n in positive/negative direction.

For example,

  • n = 2, then "IJK" will become "KLM"
  • n = 3, then "IJK" will become "LMN"
  • n = -2, then "AJK" will become "YHI"
    • We do the shifting in a cyclic manner, that is, perform left shift 1 on "A" will become "Z"; right shift 2 on "Y" will become "A"

Actually, this encryption is the well-known Caesar chiper.

Input

Input consists of three UPPERCASE English characters and an integer nseperated by a whitespace character.

The three uppercase English characters is the Caesar's message, n is the shift amount mentioned above (positive for right shift, negative for left shift).

It is guaranteed that -2147483648 <= n <= 2147483647.

Output

Print Caesar's message after encryption (three UPPERCASE English character).

Remember to print a '\n' at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss




12013 - multiplication   

Description

Cookie multiplication

Jane has two types of cookies (of number N and M, respectively), and she uses a magic spell to produce more cookies (N * M in total).

However, there are many cookies. Jane asks you to help her calculate the number of new cookies she can make.

Input

3 integers K, N, M in order.

N , M means the number of cookies.

If the digits of new cookies is smaller than K,

please left pad with zeros up to K digits.

Data range:

0 <= N, M <= 2^32-1

1 <= K <= 1000000

Output

Output a single line with the number N * M, and a '\n' at the end.

Hint: overflow , printf skill

 

The * Modifier with printf() and scanf()

printf()

Suppose that you don't want to commit yourself to a field width in advance but rather you want
the program to specify it. You can do this by using * instead of a number for the field width, but
you also have to use an argument to tell what the field width should be. That is, if you have the
conversion specifier %*d, the argument list should include a value for * and a value for d. The
technique also can be used with floating-point values to specify the precision as well as the field
width. 
// uses variable-width output field
#include <stdio.h>
int main(void)
{
    unsigned width, precision;
    int number = 256;
    double weight = 242.5;
    printf("What field width?\n");
    scanf("%d", &width);
    printf("The number is :%*d:\n", width, number);
    printf("Now enter a width and a precision:\n");
    scanf("%d %d", &width, &precision);
    printf("Weight = %*.*f\n", width, precision, weight);
    printf("Done!\n");
    return 0;
}
-------------------------------------------------------------------------------------------------------------------------------
Sample run
What field width?
6
The number is :   256:
Now enter a width and a precision:
8 3
Weight =  242.500
Done!
 
scanf()
 
The * serves quite a different purpose for scanf(). When placed between the % and the specifier
letter, it causes that function to skip over corresponding input.
This skipping facility is useful if, for example, a program needs to read a particular column of a
file that has data arranged in uniform columns.
// skips over first two integers of input
#include <stdio.h>
int main(void)
{
    int n;
    printf("Please enter three integers:\n");
    scanf("%*d %*d %d", &n);
    printf("The last integer was %d\n", n);
    return 0;
}
-------------------------------------------------------------------------------------------------------------------------------
Sample run
Please enter three integers:
2004 2005 2006
The last integer was 2006


If you don't know how to search more information, you can look at this reference.

It really helps.

http://www.cplusplus.com/reference/cstdio/printf

Sample Input  Download

Sample Output  Download

Tags




Discuss