| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 14822 | Tic Tac Toe Winner |
|
| 14823 | Same direct supervisor |
|
Description
This program simulates a simple tic-tac-toe (圈圈叉叉) game.
We use numbers 1–9 to represent the positions on the tic-tac-toe board as follows:
1 2 3 4 5 6 7 8 9
Each move is represented by one of these numbers.
The input is a sequence of up to nine integers, indicating the order in which two players make their moves.
Player 1 moves first, followed by Player 2, and so on.
That is, the values in the odd positions of the input sequence represent player 1’s moves, and those in the even positions represent player 2’s moves.
If at any point a move is illegal (that is, a player attempts to play in a cell that is already occupied), the program should immediately output:
illegal move
If one of the players wins, the program should output the number of the last move made by the winning player.
The test cases for this problem guarantee that there are only two possibilities:
-
One player wins, or
-
An illegal move occurs.
No tie (沒有和局) or simultaneous win conditions will appear.
Reference structure and function definitions:
The following C code structure and function prototypes are provided as a reference framework:
typedef struct {
int board[3][3];
} TicTacToe;
void init (TicTacToe *ttt);
int play (TicTacToe *ttt, int color, int x, int y);
int win (TicTacToe *ttt, int color);
Function descriptions:
-
initinitializes the Tic Tac Toe board by setting all cells to 0. -
playattempts to place a piece of the specified color atboard[x][y].-
If successful, the position is filled and the function returns 0.
-
If the cell is already occupied, it returns -1.
-
-
winchecks if the given color has achieved a winning condition (three in a row).-
Returns 1 if that color wins, otherwise returns 0.
-
Input
A line containing between 1 and 9 integers, representing the sequence of moves in a tic-tac-toe game.
Output
If an illegal move occurs, print
illegal move
Otherwise, print the number (1–9) corresponding to the last move made by the winning player.
Ensure that the output, including formatting, exactly matches the provided samples.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
You are given information about a group of employees in a company.
Each employee has the following attributes:
typedef struct {
int id;
char firstname[32];
char lastname[32];
int boss_id;
} employee;
-
a unique employee ID (
id) -
a first name (
firstname) -
a last name (
lastname) -
the employee ID of their direct supervisor (
boss_id)
If an employee’s boss_id is the same as their own id, it means that person is the top boss.
All employees and their supervisors appear in the input list.
Two employees A and B share the same direct supervisor if there exists a person C such that both employees have boss_id = C.id.
You need to determine, for several pairs of employees, whether they have the same direct supervisor.
Input
-
The first line contains an integer
n, the number of employees. -
The next
nlines each contain:
id firstname lastname boss_id -
The next line contains an integer
m, the number of queries. -
The next
mlines each contain the names of two employees:
firstname1 lastname1 firstname2 lastname2
All queried employees exist in the list and are distinct.
Output
For each query, output yes if the two employees have the same direct supervisor, otherwise output no.
Ensure that the output format exactly matches the sample.