| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10915 | cheatsheet |
|
| 12303 | Operation on Sequence |
|
| 12392 | Heatstroke Bamboo Rats 2 |
|
| 12395 | Storm Area 51 |
|
Description
printf() and scanf() format
printf("%d", n);
FORMAT ARGUMENT TYPE
%d, %i int decimal
%u unsigned int
%x unsigned int hexadecimal
%#x unsigned int hexadecimal with prefix 0x
%f double
%Lf long double
%e, %E double scientific notation
%c int to print a character
%s char * string (character array ended with '\0')
%p void * print memory address
%g, %G double %f or %e depending on the length
scanf("%d", &n);
FORMAT ARGUMENT TYPE
%d int * &n, store the input integer in n
%ld long *
%lld long long *
%u unsigned int *
%f float * read float
%lf double * read double
%Lf long double * read long double
%c char * read 3 characters %3c
%s char * read a string until whitespace
%n int * with %s, to get string length
char a[100]; int len;
scanf("%s%n", a, &len);
len will have the string length
Frequently used functions
#include <string.h>
char str[10];
scanf("%s", str);
to get the string length using strlen(str)
#include <ctype.h>
isspace(ch), islower(ch), isupper(ch), isdigit(ch)
isalpha(ch), toupper(ch), tolower(ch)
To create a 5-by-5 two-dimensional array, we need to write
int a[5][5];
It will be indexed as follows:
|
a[0][0] |
a[0][1] |
a[0][2] |
a[0][3] |
a[0][4] |
|
a[1][0] |
a[1][1] |
a[1][2] |
a[1][3] |
a[1][4] |
|
a[2][0] |
a[2][1] |
a[2][2] |
a[2][3] |
a[2][4] |
|
a[3][0] |
a[3][1] |
a[3][2] |
a[3][3] |
a[3][4] |
|
a[4][0] |
a[4][1] |
a[4][2] |
a[4][3] |
a[4][4] |
How to read the following data?
1 2 3 4 5 e
#include <stdio.h>
int main(void)
{
int x;
while (scanf("%d", &x) == 1) {
printf("x=%d\n", x);
}
return 0;
}
How to read the following data?
2
L 5 2
D 5 3
#include <stdio.h>
int main(void)
{
char ch;
int i, n, row, col;
scanf("%d", &n);
for (i=0; i<n; i++) {
while(getchar()!='\n');
scanf("%c%d%d", &ch, &row, &col);
}
return 0;
}
Using for loops to print a two-dimensional array
for(i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
printf("%5d", A[i][j]);
}
printf("\n");
}
Using bubble sort to rearrange an array A
for (i = 0; i < n; i++) {
for (j = 1; j < n; j++) {
if (A[j] > A[j-1]) {
/* swap A[j] A[j-1] */
}
}
}
operators:
! && || == != + - * / %
> < >= <=
How to avoid common errors and how to debug for OJ
1. Put the arrays in the 'global' area. Set their size bigger than required. Avoid using variable-length arrays (e.g. int arr[n];). Keep the array size fix (e.g., int arr[1000];).
2. After writing the code for reading input data, you may print out the data to check if your code reads them correctly. Do not proceed to write subsequent code before you confirm that.
3. If your program crashes, usually it is caused by memory related errors. Check the ranges of for-loops to see if your code attempts to read or write the elements out of the arrays’ boundary.
#include <string.h>
strstr(str1,str2)
return a pointer to the first occurrence in str1 of the entire sequence of characters specified in str2, or a null pointer if the sequence is not present in str1.
strcmp(str1,str2)
Compare two strings.
return
|
|
if the first character that does not match has a lower value in ptr1 than in ptr2 |
|
|
if the contents of both strings are equal |
|
|
if the first character that does not match has a greater value in ptr1 than in ptr2 |
strncmp(str1,str2,num)
Compares up to num characters of the C string str1 to those of the C string str2
return
|
|
if the first character that does not match has a lower value in str1 than in str2 |
|
|
if the contents of both strings are equal |
|
|
if the first character that does not match has a greater value in str1 than in str2 |
#include <stdlib.h>
malloc(size)
return a pointer to the memory block allocated by the function.
Input
Output
Sample Input Download
Sample Output Download
Tags
Discuss
Description
No description, literally. I'm tired.
_(:3∠」)_
-
You have a sequence
a. Initially,ahas exactly one integer. You're at the place of the1stelement. -
There are some operations below:
-
insert <val1> <val2>: insert<val2>number of elements, all with value<val1>. Insert them next to your position. -
erase <val>: erase<val>number of elements next to you. -
move <value>: Move<value>number of indexes forward. Note that<value>might be negative, which means you might move forward or backward. -
show: Start from your position, output the sequencea. Each element separated by a space. Note that there should be no space at the end but a'\n'.
-
For example: a = {2}, and execute operations below:
-
insert 3 6//a={2,3,3,3,3,3,3}, you're at the 1st position. -
insert 1 1//a={2,1,3,3,3,3,3,3}, you're at the 1st position. -
erase 2//a={2,3,3,3,3,3}, you're at the 1st position. Erase 1 and3. -
move 5//a={3,2,3,3,3,3}, you're at the 1st position. Originally was the 6th position. -
erase 3//a={3,3,3}, you're at the 1st position. Erase the first2and two3. -
show// print3 3 3. Note that there should be a'\n'at the end.
Input
The first line contains an integer x, indicates the first element in a.
The next line contains an integer n, indicates the number of operations.
There are n lines below. Each line contains exactly one operation.
1 <= n <= 3000. All numbers in a are in int range. We guaranteed that there must be at least 1 element in a, and the number of insert and erase elements won't exceed 3000.
Also, the total elements of a won't exceed 3000.
Output
Output the correct a if there's show operation.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
This bamboo rat seems to have heatstroke, we might as well ......
── Brothers HuaNong
Brothers HuaNong feed a lot of bamboo rats. They do love to eat bamboo rats! However, some of the rats seems to have heatstroke. Brothers HuaNong couldn't bear to watch them suffer, and we all know how Brothers HuaNong treat those heatstroke rats...

Every bamboo rat has its level of heatstroke(中暑程度), Brother HuaNong would randomly choose a number . If there's a rat with level of heatstroke equals to , Brother HuaNong would think that the rat has heatstroke and eat it.
However, if they just keep eating those heatstroke rats, they would eat up all the rats eventually, so they also have to buy bamboo rats in case that too many rats have heatstroke.
You are hired by Brothers HuaNong. Brothers HuaNong will give you the level of heatstroke of every bamboo rats and several numbers . Your task is to help them find out if there's rats that have heatstroke.
This problem is partial judge. You are going to implement the following functions:
-
void build_tree(Node **now, int *arr, int l, int r)When this function is called, you should build a binary search tree by the array
arr. -
int query_heatstroke(Node *now, int x)This function is used to ask if there exists a node with level equals to x.
-
void eat_rat(Node **root, int x)This function will delete one node with level equals to x.
-
void buy_rat(Node **root, int x)This function will insert a node with level equals to x.
Take sample as an example, initially, the level of heatstroke of the rats would be (1, 8, 309).
heatstroke 8: Exists a rat with level 8, eat it. The sequence becomes (1, 309).heatstroke 8: No rat with level 8. No dinner tonight.heatstroke 1: Exists a rat with level 1, eat it. The sequence becomes (309).heatstroke 309: Exists a rat with level 309, eat it. The sequence is now empty.buy 5: Add a new rat with level 5. The sequence becomes (5).heatstroke 5: Exists a rat with level 5, eat it. The sequence is now empty.
Input
The first line is an integer n, which indicates the number of bamboo rats.
The next line contains integers, indicate the level of heatstroke of every bamboo rat sorted in ascending order.
The third line is an integer q, which means there are queries below.
There are lines below.
In each queries, there are two operations:
heatstroke x: eat a rat with level equals to if there exists one.buy x: buy a rat with level equals to x.
0 <= n <= 10^4, 1<= q <= 10^4, 1<= x <= 10^9, the level of bamboo rats have the same range as x.
Output
For each heatstroke operation, output "We might as well eat it." if there's a rat with the corresponding level, otherwise output "No dinner tonight."
Sample Input Download
Sample Output Download
Partial Judge Code
12392.cPartial Judge Header
12392.hTags
Discuss
Description
An fandom anime opening of Area51 Raid event.
If we naruto run, we can move faster than their bullets.
── Unknown naruto runner
"Storm Area 51, They Can't Stop All of Us" is an event that invites everyone to intrude into the famous America military base "Area 51" on Sep. 20, 2019. In this event, participants are asked to use naruto run to intrude Area 51 so that they can move faster than their bullets.
However, performing naruto run challenges the control of Chakra(查克拉) of the runner. They have to control the flow of Chakra and distribute it appropriately so that they could be able to run steadily.

A runner run over the camera. Shot in 1/1000 sec. The original report is here.
On every step, a pre-order binary expression and some values would cross runners' mind. Runners needs to rearrange the binary expression into in-order and calculate the answer of this expression, so that they can naruto run steadily and dodge those bullets.
You are an adviser of this event. Somehow you can read the runners' mind and tell them the answers of these expressions. You're going to write a program to help them, otherwise they will be hit by bullets.
Because naruto run is a simple ninjutsu(忍術), the expression won't be too complicated, so the variables in an expression won't exceed 3(). And we don't care about the parentheses.
Take the sample as example:
We use the pre-order binary expression the build a syntax tree, the tree should look like the following graph:
Now, we can write down the in-order: x+3*y/4. Note that we don't add spaces or parentheses.
And we know that , then calculate the answer: .
Note that we only pick the integer part to calculate.
Input
The first line contains the whole expression in pre-order. The length of the input string wouldn't exceed 100.
The input expression would contain:
- variable
- operator
- integers in range
The second line contains three integers represent , , , respectively.
. You don't have to worry about overflow or underflow.
Note that there will be a space after every operator, number, and variable. Please refer to the sample.
Output
On the first line, output the expression in in-order. There should be no space between every operator, number, and variable.
On the second line, output the result of this expression.