2628 - I2P(I)2022_Yang_mid1 Scoreboard

Time

2022/11/01 18:30:00 2022/11/01 21:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11110 cheat_sheet (mid2)
12230 ReadFirst
12441 Palindrome
13634 Indentation Revenge
13670 NOT Easy Gomoku Validator

11110 - cheat_sheet (mid2)   

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)
to compare two strings strcmp(str1, str2) ==0 if equal
to compare the first n chars of two strings strncmp(str1, str2, n) ==0 if equal
to copy str2 to str1 strcpy(str1, str2)
to append a copy of str2 to str1 
strcat(str1, str2)
to copy the first n chars of str2 to str1 strncpy(str1,str2, n) remember to add '\0' to str1
#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:

 


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 ap

for (i = 0; i < n-1; i++)
{
    for (j = 0; j < n-1-i; j++)
    {
        if (ap[j] > ap[j + 1])
        {
            temp = ap[j];
            ap[j] = ap[j + 1];
            ap[j + 1] = temp;
        }
    }
}

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.

*(a+i) is equivalent to a[i]
(a+i) is equivalent to &a[i]

Input

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss




12230 - ReadFirst   

Description

1. Grading
  • Midterm 1 accounts for 10% of your semester grade.
  • The grade of your mid-1 is computed as follows:
    Let P1 be 12441, P2 be 
    13634, P3 be 13670.
    Grade = [Score(P1) + Score(P2) + Score(P3)] * 
    0.5,
    where Score(Pi) is the number of testcases you earned for problem Pi.
2. Recommended problem-solving order
  • {12441} --> {13634--> {13670}

Input

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss




12441 - Palindrome   

Description

Palindrome is a string that is identical to its reverse, like "level" or "aba".  Check whether a given string is a palindrome or not.

Input

The input consists of multiple lines. Each line contains a string. The length of each string is less than 100000.  The number of test case is less than 1000.

Output

For each test case, output "Yes" if it's a palindrome or "No" if it's not a palindrome in a line.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss




13634 - Indentation Revenge   

Description

You're now in a bad mood since you quarreled with your best friend. 

Recently, you keep convince you that using semicolons for indentation is the best way to code in C. Although you have listed several benefits of using semicolons for indentation, your friend still can't understand the beauty of semicolon indentation, instead, he thinks you're crazy and refuse to read your code.

What's worse, your friend has secretly turned all your codes to space indentation while you were sleeping, which made you very angry. Now, your friend leaves his computer on his desk for dinner, and he forgot to lock his computer. It's a great chance to start your revenge.

Given lines of compilable C code. Currently, the code is indented by spaces, and now you want to rewrite this code using semicolons for indentation.

In other words, you are going to do the following operations:

  • For every single line, turned every prefix space into semicolons.
  • Remove the semicolon at the end of every line.
  • Add a line // surprise<3 at the last line of the whole code to taunt him (remember to print '\n' at the end of the line).

Input

 Lines of compilable C code, terminated by EOF.

Output

The code using your special coding style.

Sample Input  Download

Sample Output  Download

Tags

FlyHighHigh



Discuss




13670 - NOT Easy Gomoku Validator   

Description

CodePen - Gomoku Game (5 in a row)
+
-
try to get 5 in a row!
Game Source

Gomoku, also known as 五子棋, is a kind of board game with the following rules.

Players alternate turns to place a stone of their color on an empty intersection. Black plays first. The winner is the first player to form an unbroken chain of five stones horizontally, vertically, or diagonally. And the game will stop immediately if someone wins the game.

MM loves playing Gomoku with his friends(if there are any), but his friends found it boring playing with him.

Therefore, it is not surprising for his friends to play the Gomoku indifferently, and they may ignore the rules of the Gomoku sometimes.

So MM played \(T\) games of Gomoku today, and you are given the results of these \(T\) games of Gomoku.

For each game, please tell him whether the result of this game can be generated through some valid game processes, or someone who played this game wasn't paying attention to the rules.

Note that MM and his friend may not finish the game, so it should be considered valid even if there's no winner.

Hint:

Hint1:
Testcases 1-2: The number of black stones and the number of white stones should be equal; or the number of black stones should be equal to the number of white stones plus 1.

Hint2:
Testcases 3-4: There should be only 1 winner at any moment. If the black stone has 5-in-a-row, the white stone should not have any 5-in-a-row; otherwise, the board should be declared illegal; vice versa.

Another Hint
  • The first thing to check is whether the difference between the number of black and white stones are at most 1. And the number of black stones can't be less than the number of white stones.
  • The second step is to check whether there's at most one winner, and the winner should be the one who placed the last stone (we could know that from the number of stones each player placed). If not, it is clear that this result is illegal. On the other hand, if there's no winner, it is clear that it's legal.
  • So now we're facing the case that there's exactly 1 winner. To ensure that the game ends right after someone wins, we can iterate thru all possible "last placed stone". A stone can be the "last placed stone" if and only if the color of this stone is the same as the winner's color. And before the stone was placed, there should be no winner. The result is considered legal if there exists at least 1 valid "last placed stone", or illegal otherwise.

Input

The first line contains an integer T, which is guaranteed to be less than or equal to 20.

The following are the result of each game, where each game is represented by a 15 x 15 board which contains {'0', '1', '2'} only.

'0' means that the grid has not been placed any stone, '1' means that the grid is placed with the first player's stone, '2' means that the grid is placed with the second player's stone.

It is guaranteed that in 2/6 of the testdata, there's no winner.

It is guaranteed that in 4/6 of the testdata, there's no more than two 5-in-a-row.

There's no further constraints in the last 2/6 of the testdata.

Output

For each game, print "Yes\n" if the result can be generated through some valid game processes, or "No\n" otherwise.

Sample Input  Download

Sample Output  Download

Tags

LoseLightLight



Discuss