Bo2SS

Bo2SS

2 Start the programming journey in vim

Programming with vim#

  • Save file and exit: , ZZ
  • In Linux, everything is a file
    • Executable program a.out is also a file, a binary file
  • .cpp files can contain C code, but not vice versa (C++ code in .c files)
    • Note: Some macros under C11 standard are not compatible with C++

C programming conventions#

  • Mainstream coding conventions in China: ali + google, baidu + google. Refer to Google C++ Style Guide
  • PS:
    • Leave a blank line between two functions: one empty line is enough
    • Generally use CamelCase naming convention: MyName (capitalized), myName (lowercase)

How to debug a program#

  • Common sense: The program defaults to using main() function as the entry point
  • Function encapsulation: After defining a function, have you called it?
  • When encountering compilation errors: Find the error from top to bottom, debug
  • When the result is unexpected: Try using printf to output the value of variables

How to use and improve programming skills with HZOJ#

HZOJ-69: Start of School Exam 2: Date Judgment#

  • Image

Sample Input

1991 1 30
1991 1 32

Sample Output

Yes
No
  • Approach
    • Check for invalid input, check if the number of days in a month is reasonable (leap year)
    • Two versions
      • Complex if-else statements: heavily nested
      • Trade space for time: create an array of days in each month
  • Code

Reflections on prime number problems#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.