| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11648 | 2D character position |
|
| 11650 | Rectangle |
|
| 11652 | Bit reverse mid |
|
| 11654 | yang_cheatsheet |
|
Description
Determine the positions of each letter in a given 2D character array. Then output the positions of each letter in lexicographical order. For each letter, output its positions from left-top to right-bottom.
Input
First, you will get an integer N, N <= 2000, meaning you will get an N*N 2D character array. Then, you will get N lines of input and N characters in each line.
Output
Please output each position using the format (x,y), and then add a space between two positions. Remember to add ‘\n’ at the end of the outcome of every letter.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
There are N points on the Cartesian coordinate system. Now we have to find how many rectangles we can draw with those N points. Notice that we only need to find the rectangles whose 4 edges are parallel with the X and Y axes.
For example, we can draw 3 rectangles in the following figure.

Input
The first line is the number T (1<=T<=15), meaning that there are T times of operation.
The second line is N, meaning that there are N points for every operation.
For the next N lines, each line contains two numbers, x and y, meaning that the position of the point is (x, y). Besides, there won't be two points on the same position.
Output
For every operation, please output the max number of rectangles we can draw.
### Hint1:
Implement two loops to find the left-top and the right-bottom points of each possible rectangle, and use these two points for judging.
### Hint2:
- In test case 1, N<=4, -1000000000 <= x, y <= 1000000000.
- In test case 2, N<=100, -1000000000 <= x, y <= 1000000000.
- In test case 3, N<=300, -1000000000 <= x, y <= 1000000000.
- In test case 4, N=2000, -100000 <= x, y <= 100000, all the points are only on two lines parallel to y-axis.
- In test case 5, N<=500, -1000000000 <= x, y <= 1000000000.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Nymphia is reading an eight-digit binary number consisting of 0s and 1s through a mirror. Because right and left are reversed in the mirror, Nymphia gets a wrong number when she directly converts the binary number to the corresponding decimal number according to the order she saw in the mirror. Can you help Nymphia correct this wrong number?
Input
Only a number N, 0<=N<=2^8
Output
Please output a decimal number with correct interpretation, and be sure to put ‘\n’ at the end.
Sample Input Download
Sample Output Download
Tags
Discuss
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
%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");
}
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.