| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12448 | Hu_cheatsheet |
|
| 12932 | Drop the ball |
|
| 12967 | Evaluate the expression |
|
| 12968 | Gomoku |
|
Description
printf() and scanf() format
printf("%d", n);
FORMAT ARGUMENT TYPE
%d, %i int decimal
%lld long long
%llu unsigned long long
%u unsigned int
%x unsigned int hexadecimal
%#x unsigned int hexadecimal with prefix 0x
%f double
%Lf long double
%c char to print a character
%s char * string (character array ended with '\0')
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");
}
logical and comparison operators operators:
! && || == != > < >= <=
arithmetic operators:
+ - * / %
bitwise operators:
& | ^ << >> ~
int strcmp(const char *lhs, const char *rhs);
int strcat(const char *lhs, const char *rhs);
int strcpy(const char *lhs, const char *rhs);
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.
Note : If you are using visual studio, add #pragma warning(disable:4996) in the first line so that you can use scanf on your local machine.
Input
Output
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a board with N rows and M columns, the rows are numbered from 1 to N from top to bottom, and the columns are numbered from 1 to M from left to right. Each element has one diagonal wall which either runs from top-left corner to bottom-right corner, or runs from top-right corner to bottom-left corner. Now given Q queries, you have to output which column the ball will fall out at the bottom row if you put it on top of the board at specific column. (The ball will naturally fall down due to gravity.)
The following figure is a sample. If you drop the ball at column 2, the ball will fall out at the left side. If you drop the ball at column 5, the ball will stuck in the board. If you drop the ball at column 3, the ball will eventually fall out at column 2.

Input
First line contains two integers which represent n, m respectively. (1 <= n, m <= 500).
The following N lines which have M characters in each line represent the board. '/' means the wall runs from top-right corner to bottom-left corner, and '\' means the wall runs from top-left corner to bottom-right corner.
Next line contains an integer Q which denotes the number of querys. (1 <= Q <= 100).
Then, the following Q line, each line has one integer which represents the starting column to drop the ball.
Output
For each queries:
If the ball fall out at the right side, you should output "Right!".
If the ball fall out at the left side, you should output "Left!".
If the ball stuck at the board, you should output "Stuck QQ".
Otherwise, you should output "Position: x". x represents which column the ball fall out at the bottom row.
Remember to output '\n' at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
You are given a string of legal mathematical expression, which contains integers and arithmetic signs (only addition or subtraction) between them, with at most one parenthesis.
Please evaluate and output the result.
Input
The input contains a single line of math expression, which has N integers and N-1 signs ('+' or '-') between them.
1 ≤ N ≤ 100, integers are ranged from 0 to 100000000, and there will be no leading zeros.
In the first five testcases, there will be no parenthesis. We encourage you to solve these testcases first.
Output
Please output the evaluated result of the expression, followed by a newline character.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Gomoku(Five in a Row) is a two-player board game. Two players(black and white) take turns placing a stone of their color on an empty intersection. The first player who forms an unbroken chain of 5 or more stones(horizontally, vertically, or diagonally) is the winner.
You have to solve q tasks. In each task, you need to output the winner(there may be no winner) for the given Gomoku board.
And in this problem:
- gridsize of the board is considered 15 x 15
- black is always the first player who starts placing the stone
- the given board must be valid
- don't consider any variation of the rule(like renju, Swap2...)
Here are three illustrations about the sample.
![]() |
![]() |
![]() |
| the board given in the first task | the board given in the second task | the board given in the third task |
The content of the sample is so many. So it's not recommended to type the sample manually to test your code.
Input
The first line contains an integer q (1 ≤ q ≤ 100) – the number of tasks you have to solve.
For each task, there are exactly 15 lines which contain exactly 15 characters each – the board you are given. 'b' and 'w' represent the stone placed by black and white respectively. And '.' represents an empty intersection.
Output
For each task output the winner(output "none" if there is no winner).
Remember to print a newline('\n') at the end of each line(task).


