1894 - I2P(I)2019_Hu_final_exam_makeup2 Scoreboard

Time

2020/01/16 16:00:00 2020/01/16 18:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12448 Hu_cheatsheet
12461 Reservoir's Volume
12560 Permutation With Repetition
12594 Implement Linked List

12448 - Hu_cheatsheet   

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




12461 - Reservoir's Volume   

Description

As the member of Water resources bureau (水利局), Your job is to compute the total volume of Reservoir (水庫) by an elevation map.

Take an example below:

The above elevation map can be represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 unit of water is the total volume of Reservoir (水庫)

Note that: 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

N

S_1 S_2 ... S_N

Given an elvation map with the length of N ( 3 <= N  < 3000) with each element S_i (0 <= S_i < 1000) 

Output

Compute the total volume of Reservoir (水庫).(followed by an newline character at the end of output string)

Sample Input  Download

Sample Output  Download

Tags




Discuss




12560 - Permutation With Repetition   

Description

Given a string of length n, print all permutation of the given string. and repetition of characters is allowed!.

There are few examples below:

Case1:

Input: A

output: A

 

Case2:

Input: AB

output: AA AB BA BB

Input

S

S: the input string ( 2 <= len(S)) < 7)

Note : the input string only contain alpha characters included upercase and lowercase.

Note : each element of input string is different.

Output

Ouput the permutation with repetition pattern (each output string followed by a newline characters)

Sample Input  Download

Sample Output  Download

Tags




Discuss




12594 - Implement Linked List   

Description

Given a link list structure named Node.

typedef struct _Node {

    int data;

    struct _Node *next;

} Node;

In this problem, you need to implement five operation for the linked list. 

func1: Node* createList(int *a, int size);

func2: void push_front(Node** head, int val);

func3: Node* copyList(Node* head);

func4: void deleteElementByIdx(Node** head, int idx);

func5: void SwapElementByIdx(Node** head, int idx1, int idx2);

func1: using an array to build the link list

func2: append the input value to the first element in the linked list

ex:  origin linked list : [0, 1, 2, 3], when call the function push_front(&head, 5). the final linked list will be [5 ,0 ,1, 2, 3]

func3: copy the original link list (not directly to assign it)

func4: delete the element by its index (begin from 0)

ex: origin linked list : [0, 1, 2, 3], when call the function deleteElementByIdx(&head, 0). the final linked list will be [1,2,3]

note that: if the idx out of range. you should ignore the delete operation

func5: swap the element in linked list by given idx1 and idx2 (both begin from 0)

ex: origin linked list: [0, 1, 2, 3], when call the function SwapElementByIdx(&head, 0, 3). the final linked list will be [3, 1, 2, 0]

note that: if the idx1 or idx2 out of range, you should ignore the swap operation 

Note: We guarantee that function 1, 3~5 will not operate on an empty list.

Input

T M

S1 .. SM

t1_command

...

tT_command

T: the number of command ( 0 <= T < 200)

M: the number of initial linked size (0 <= M <= 2000)

Si: the value of the initial array (0 <= Si <= 1000)

ti_command: the command description

(0: push_front, 1: clone, 2: delete, 3: swap)

Hint: 

testcase1 : contain only createList operation

testcase2: contain only push_front operation

testcase3: contain createList , push_front, copyList operation

testcase4: contain createList , push_front , copyList operation, deleteElementByIdx

testcase5: contain all operation 

Output

Output the element in linked list whenever the operation be called. 

Sample Input  Download

Sample Output  Download

Partial Judge Code

12594.c

Partial Judge Header

12594.h

Tags




Discuss