1431 - CS I2P 2018 Lee Mid 1 Scoreboard

Time

2018/04/13 16:00:00 2018/04/13 18:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11462 cppreference
11536 Triangle
11879 Four of a kind
11881 Reverse digits
11884 lee_cheatsheet

11462 - cppreference   

Description

版本:

20180311

 

使用說明:

請下載code或header(兩個是同個檔案)

把附檔名從.cpp改成.zip

解壓縮後

reference>en>cpp.html

即可看到官方文件

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

11462.cpp

Partial Judge Header

11462.h

Tags

CPP Reference



Discuss




11536 - Triangle   

Description

Please print a triangle according to the input.

Input

The input contains three numbers: LAYER, INC, and SHIFT.

LAYER: Denoting the total layers in the triangle. (1 <= LAYER <= 20)

INC: For each layer, you should extend INC stars ('*')  toward left and right (e.g. If INC = 1, then the number of stars in each layer is 1 3 5 7....; if INC = 2, the the number of stars in each layer is 1 5 9 13 ...; if INC = 0, then the number of stars in each layer is 1 1 1...). (0 <= INC <= 39)

SHIFT: Denoting the distance for right shifting for the whole triangle. (0 <= SHIFT <= 9)

Output

Please reference the sample IO (You can view the download file).

The output should contain a complete triangle, and there are SHIFT spaces (' ') at the left of the lower-left star in the trinagle.

There are no tailing spaces at the end of each layer, and there is a newline character ('\n') at the end of each layer (including the last layer).

Sample Input  Download

Sample Output  Download

Tags




Discuss




11879 - Four of a kind   

Description

In this problem, you are to write a program to check whether a set of five cards forms a "four of a kind". The input contains T sets of 5 cards to verify the correctness of your program.

Four of a kind, also known as quads, is a poker hand containing four cards of the same rank and one card of another rank (the kicker), such as 9♣ 9♠ 9♦ 9♥ J♥ ("four of a kind, nines"). It ranks below a straight flush and above a full house.

There are 624 possible four of a kind hands and 156 distinct ranks of four of a kind when using a standard 52-card deck. Each four of a kind is ranked first by the rank of its quadruplet, and then by the rank of its kicker. For example, K♠ K♥ K♣ K♦ 3♥ ranks higher than 7♥ 7♦ 7♠ 7♣ Q♥, which ranks higher than 7♥ 7♦ 7♠ 7♣ 10♠. Four of a kind hands that differ by suit alone, such as 4♣ 4♠ 4♦ 4♥ 9♣ and 4♣ 4♠ 4♦ 4♥ 9♦, are of equal rank.

Input

The first line contains an integer T, representing the number of sets.

The next T lines contain 5 cards in each given set, separated by whitespaces.

The cards would range from : {A, 2, 3, 4, 5, 6, 7, 8 ,9 ,10, J, Q, K}.

(In this problem, you don't need to consider the suit of each card. No card set of 5 cards contains 5 identical cards.)

  • 1 ≤ | T | ≤ 10000

Output

For each set of cards, please print 'YES' if the set is a "four of a kind"; otherwise, please print 'NO'.

Remember to print '\n' after each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11881 - Reverse digits   

Description

The input is a three-digit decimal integer N that consists of digits [1-9] except 0. For example, 489 is such a number, while 101 is not. The task is to reverse the order of the digits in N to get a new three-digit number M, and compute |N-M|/10. |N-M| means the absolute difference of N and M. For example, if N is 489, then M is 984, and the answer should be 49.5.

Input

A three-digit integer consisting of [1-9] except 0

Output

The absolute difference of the input number and its reversal divided by 10.

The answer should be expressed as a floating point number with precision to the first decimal place. For example, 333.0 or 736.5

Note that you do not need to print ‘\n’ at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11884 - lee_cheatsheet   

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 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.

Input

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss