| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11112 | Big Number |
|
| 11127 | Binary representation&sum |
|
| 12880 | Let's build a RPG game |
|
Description
Replace the ??? in the following code so that the program can correctly compute
the square of the number entered by the user.
Assume that the input number is always an 8-digit positive integer.
* Note that the output format is always 16-digit wide with space prepended if needed.
For example,
(11111111)^2 = _123456787654321
_ is a space character.
#include <stdio.h>
/* 2016/09/22 */
int first4(int x){
return x/10000;
}
int last4(int x){
/* The operator % in C computes the remainder after division.
For example, the answer of 23%7 will be 2.*/
return x%10000;
}
int first8(int x){
return x/100000000;
}
int last8(int x){
return x%100000000;
}
int shift4(int x){
return x*10000;
}
int main(void){
int x;
int a, b;
int c1, c2, c3;
/* Assume that the input is always an 8-digit positive integer. */
scanf("%d", ???);
a = first4(x);
b = last4(x)
c3 = ???;
c2 = ???;
c1 = ???;
printf("%4d%08d%04d", ???, ???, ???);
/* %04d will display a 4-digit number and add 0 as padding before the number if necessary */
return 0;
}
Assume that the input 8-digit integer
x can be expressed by a*10000 + b .The square of x can be expressed as a*a*100000000 + 2*a*b*10000 + b*b .We may partition the computation into three parts.
Input
The input is always an 8-digit positive integer
Output
the square of input .
Note that you do not need to print ‘\n’ at the end of the output.
Sample Input Download
Sample Output Download
Tags
Discuss
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
Description
"RPG games are fun to play, as a CS student, it must be easy for you to build a RPG game, right?"
Your younger sister asked.
To impress your younger sister and makes her happy, you decide to build a RPG game.
As a starter, you want to build the combat system first.
The combat system is used for stimulate the battle between the player and the enemy.
Both the player and the enemy have 3 properties, HP (Health point), ATK (Attack damage), and DEF (Defence).
When the player attack the enemy, the enemy also attack the player at the same time.
The enemy HP will reduce (Player ATK - Enemy DEF) points, and the the player HP will reduce (Enemy ATK - Player DEF) points.
When one's HP is non-positive, the battle end.
Output the process of the battle system!
ouo.
Input
Input contains 2 lines.
The first line contains 3 integers, P_HP, P_ATK, P_DEF,
represent the player's HP, ATK and DEF respectively.
The second line contains 3 integers, E_HP, E_ATK, E_DEF,
represent the enemy's HP, ATK and DEF respectively.
It's a guarantee that:
1 <= P_HP, E_HP <= 1000,
20 <= P_ATK, E_ATK <= 2000,
0 <= P_DEF, E_DEF < 20.
Output
Output contains several lines.
The first line represent the battle start, output "Battle Start \^_^/". (without quotes)
Start from the second line,
output "The player dealt {} damage to the enemy and the enemy dealt {} damage to the player", (without quotes)
then output "The player has {} HP left and the enemy has {} HP left".
You should replace the {} to the correct number.
Until one's HP is non-positive, output the battle end message "Battle End \^_^/". (without quotes)