A summary of common errors in C-language correlation and algorithmic problems

Source: Internet
Author: User

Before writing the program summarizes some things, more personal, recorded in this. Continue to supplement the following.


1. Don't get too tangled up in the input. such as how to end it, or the character a to match the int to end. It's a complicated mess. You can easily limit the number of inputs.

2. If there is an ABC and ABCD in the name, it is possible to compile the ABCD and run the ABC. Because of the space.

3. The array must not be opened small. Especially when reading a file, and you do not know the maximum length, do not take it for granted, it is easy to open the array small. Mistakes are difficult to find.

4. Read the file, fscanf is too easy to make mistakes, or with getc better, especially need a line of processing, fscanf too easy too easy error ...

5. Use fgets to define the Maxline, as far as possible to define a larger bar, do not appear small error is not easy to find out. Especially when there is Chinese, you think very short, in fact, the length is very large. Don't take it for granted.

6. When using string, after #include<string>, also use namespace std;

The reasons for 7.RE are:

Modulo 0, except 0; (except 0, modulo 0, whether because the divisor is not successfully read in and 0)

The array is small and overflow;

Array out of bounds (note the range of results, not just the range of input data, the array is really open enough?) )

The dead loop waits for the read-in (for example, you are GetChar ()! = ' \ n ') and the last line does not wrap but EOF ends and the program crashes.

The program card is waiting for input

Use a pointer to a block scope variable (such as a variable created in an if statement, take a pointer to the struct pointer queue, see the wrong version of UVA 532 with pointers)

8.Output Limit exceeded means that if you enter a set of data, the result of your program is to output a certain result, the kind of dead loop output. In addition to the dead loop, Tle is an algorithmic problem.

The reasons for 9.TLE are:

There is no end mechanism. For example, you have a while (1) loop, there is a break condition, but that condition has not been satisfied, such as a bool variable, you pass in the function is not a pointer to be modified, has been unable to meet the condition out of the loop. (See UVA 699)

Algorithm time complexity is too high, infinite recursion, infinite while.

10.WA time to construct big data test to see. Also, see if the freopen is commented out.

A summary of common errors in C-language correlation and algorithmic problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.