有趣的C代码

简介:
国际C语言混乱代码大赛

http://zh.wikipedia.org/zh-cn/%E5%9B%BD%E9%99%85C%E8%AF%AD%E8%A8%80%E6%B7%B7%E4%B9%B1%E4%BB%A3%E7%A0%81%E5%A4%A7%E8%B5%9B


http://www0.us.ioccc.org/years.html

看看下面的代码,是2001年的获奖作品:
#include <stdio.h>
int l;int main(int o,char **O,
int I){char c,*D=O[1];if(o>0){
for(l=0;D[l ];D[l
++]-=10){D [l++]-=120;D[l]-=
110;while (!main(0,O,l))D[l]
+= 20; putchar((D[l]+1032)
/20 ) ;}putchar(10);}else{
c=o+ (D[I]+82)%10-(I>l/2)*
(D[I-l+I]+72)/10-9;D[I]+=I<0?0
:!(o=main(c/10,O,I-1))*((c+999
)%10-(D[I]+92)%10);}return o;}


=================================
=============  hint =============
=================================
Best short program:

Raymond Cheong
Johns Hopkins University
USA

http://www.bme.jhu.edu/~rcheong/


Judges' Comments:

To build:

make cheong

Try:

./cheong 1024
./cheong 12345678901234567890
./cheong 05305265226926441255040573044986873789

Be sure to give an even number of digits in the argument. Add a
leading 0 if needed.

The source code is nice, compact, and self documenting
as all good programs should be! :-)


Selected Author's Comments:

Operation
=========
Compile normally and run with one argument, an integer with 2n digits.
Program will return the integer part of its square root (n-digits).
For example,

> gcc -o cheong cheong.c
> cheong 1234567890
35136
> cheong 0200000000000000000000000000
14142135623730
>

Deviation from these instructions will cause undefined results. :-)


Portability
===========
This program runs normally on any ANSI C compiler and is ASCII dependent.

Strict compiling gives just one unavoidable warning
> gcc -ansi -Wall cheong.c
cheong.c:3: warning: third argument of `main' should probably be `char **'


Obfuscation
===========
The main obfuscation is the algorithm used to calculate square roots,
sometimes known as the longhand method. The basic algorithm is itself
obfuscated in that it only uses subtraction to calculate square roots.
(For a detailed explanation, check Google or see Jack Crenshaw's article
at http://www.embedded.com/98/9802fe2.htm) This program uses an even
more obscured version which includes the following:
- A single string is used to store two numbers of different lengths
- Operations are done in a weird hybrid of base 10 and base 20
- Subtraction is done addition style, i.e. 4 minus 8 equals 6 carry a -1
- Recursive calls to main()

Minor obfuscations:
- Self documenting whitespace in rectangular code block, for fun and
glory (view with fixed-width font)
- Integer constants adjusted to less meaningful values, just for added
confusion
- Hard-to-read, meaningless variable names to spite the reader

Challenges for the masses:
- What are the meanings [sic, plural] of the variable o?
- Why is (c+999)%10-(D[I]+92)%10 not equivalent to (c-D[I]+7)%10?
- How does the program terminate?
- Is the programmer sane? ;-)


Appreciation
============
Thanks goes out to Bobby Rohde for numerous suggestions on how to shorten
the program.









本文转自 h2appy  51CTO博客,原文链接:http://blog.51cto.com/h2appy/275493,如需转载请自行联系原作者
目录
相关文章
|
算法 C++ 容器
86 C++ - 算法头文件
86 C++ - 算法头文件
43 0
|
5月前
|
编译器 C语言 C++
C++中如何调用C代码
C++中如何调用C代码
77 1
|
算法 搜索推荐
快速排序的初识(附C代码)
今天看了一则关于排序算法中的快速排序。我将用自己的语言结合代码描述一下这个算法!
57 2
C语言之生成随机数方法(C代码实现猜数字游戏)
C语言之生成随机数方法(C代码实现猜数字游戏) 首先先把猜数字游戏的代码给大家暂时出来,然后我们在根据代码的步骤一步一步的推导
|
编译器 C语言
#include <stdio.h> 这段代码是干什么的?底层原理是什么?为什么这样写?
#include <stdio.h> 这段代码是干什么的?底层原理是什么?为什么这样写?
237 0
|
Linux C语言
#include <unistd.h> 这段代码是干什么的?底层原理是什么?为什么这样写?
#include <unistd.h> 这段代码是干什么的?底层原理是什么?为什么这样写?
219 0
条件编译 #if #endif #if #elif #else #endif #ifdef #if define 的使用方法 引头文件#include<> 和#include““的区别
条件编译 #if #endif #if #elif #else #endif #ifdef #if define 的使用方法 引头文件#include<> 和#include““的区别
131 0
|
编译器 开发工具 C语言
OC代码转C++代码的生成
OC代码转C++代码的生成
335 0
OC代码转C++代码的生成
|
测试技术 开发工具 数据安全/隐私保护
rsync代码同步
数据差异同步
2043 0