All winning source codes for the international C language chaos code competition: 1984-research analysis, 1984-Research Analysis

Source: Internet
Author: User

All winning source codes for the international C language chaos code competition: 1984-research analysis, 1984-Research Analysis

Anonymous. c
Source code:

int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}

The code looks dizzy. The Code formatted with the compiler is as follows:

int i;main(){    for(; i["]<i;++i){--i;}"]; read('-'-'-',i+++"hell\o, world!\n",'/'/'/'));}read(j,i,p){    write(j/p+p,i---j,i/i);}

I believe that the formatted code is still dizzy for a novice C. Let's continue to look at it. 1.1 points
This Code contains only one for loop without a loop body.
The for loop is divided into three parts (separated)
The first part is to assign values to variables.
The second part is the condition judgment statement of the loop body. When the judgment statement value is greater than 0 or a non-NULL value, execute the loop body and add the variable to 1, then make a judgment statement ........ Exit when the judgment statement is 0 or NULL.
The third part is to increase the variable by 1 or minus 1 (increase n, minus n)

To facilitate analysis, we use # define to represent strings and expressions in the code.

# Define A '-' // if you do not think this is A string, you will be wrong. This is an expression. The result is 0 if it is a character minus a character. Didn't you understand? Learn the operator priority rules. # Define B '/' // Similarly, this should not be considered a string. This is a division operation and the result is 1. # Define C "hell \ // This is the real string. Someone may ask why "hello, world \ n" is not directly written, but "hell \ o, world! \ N "// o, world! \ N ", note that \ o is in the middle of the carriage return line, why write this, in order to make you dizzy. This is an escape character. It is displayed as an English letter or an English letter. If you do not wrap the line, the compiler will prompt a warning. If you do not wrap the line, there will be no prompt after the line break. # Define D "] <I; ++ I) {-- I;}" // The author writes this string to fool you, I was fooled when I first saw it. How can I put it in the for loop? It is also a string. So don't be fooled by your eyes. The string length is 14. Why do you want to specify the string length? Hello, world! The string length is 13. Do not forget that there is \ n. Int I; main () {for (; I [D]; read (A, I ++ C, B); // The length of the D string here is 14, so the loop is 14 times .} Read (j, I, p) {write (j/p + p, I --- j, I/I );}

This read function looks a little dizzy in the for loop. Let's analyze it.

Read (A, I ++ C, B) // as we have mentioned earlier, A = 0, B = 1, and the replaced function is read (0, I ++ C, 1) Replace the parameter with the read (0, I, 1) // parameter I and the I (in the for loop body) defined above the main) it's not the same variable. Don't confuse it. The I value is I ++ "hell \ o, world! \ N ", the I in this expression is the I variable in the for loop. {Write (0/1 + 1, I --- 0, I/I); // You can also write (1, I ); // Replace the parameter I with write (1, I ++ "hell \ o, world! \ N "---) at this time, I is in the for loop I // I ++" hell \ o, world! \ N "--- 0. This string is based on variable I to get the string length. For example, if the variable I is 7, the string result is world! \ N. In fact, the string address is added with the result of variable I, and then the variable I is increased by 1. The following --- 0 is also a blind eye .}

After replacement

for(;i["]<i;++i){--i;}"];write(1,i+++"hell\o, world!\n"---0,1))

Look dizzy, haha.
i["]<i;++i){--i;}"]This string can also be written as this"]<i;++i){--i;}"[i]The calculation result is the same. Each character in the string is neither 0 nor NULL. The for condition judgment statement is executed 14 times.
In the write function, find the self-increment I of the for loop.

The running of the entire program is almost clear. Do you understand?
Review c, and I have not graduated from elementary school. If you have any unclear explanation, please speak out!

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.