鱼C论坛

 找回密码
 立即注册
查看: 2844|回复: 2

[技术交流] 国际C语言混乱代码大赛

[复制链接]
发表于 2015-1-20 20:27:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 907806863 于 2015-1-20 20:34 编辑

      国际C语言混乱代码大赛(IOCCC, The International Obfuscated C Code Contest)是一项著名的国际编程赛事,从1984年开始到2006年,每年举办一次。2006年后中止了多年,2011年又开始恢复。比赛的目的是写出最有创意的最让人难以理解的C语言代码,当然有好玩的成分,但也能充分展示C语言和程序员的强大。

其中一个例子:




#include <stdio.h>

char *a;main(int t,int _,char*
a){return!0<t?t<3?main(-79,-13,a+main(-87,1-_,

main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?

main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,

"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r
:'d*'3,}{w+K w'K:'+}e#';dq#'l
q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;#
){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw'
iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')#
}'+}##(!!/")

:t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)

:0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
"!ek;dc
i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}







(请使用GCC编译器编译)

该代码可以打印出歌曲 The Twelve Days of Christmas 的歌词
这个程序由 Cambridge Consultants Ltd.的 Ian Phillipps 编写 用于参加国际C混乱代码大赛
International Obfuscated C Code Contest.

------------
输出结果:
On the first day of Christmas my true love gave to
me
a partridge in a pear tree.

On the second day of Christmas my true
love gave to me
two turtle doves
and a partridge in a pear tree.

On
the third day of Christmas my true love gave to me
three french hens, two
turtle doves
and a partridge in a pear tree.

On the fourth day of
Christmas my true love gave to me
four calling birds, three french hens, two
turtle doves
and a partridge in a pear tree.

On the fifth day of
Christmas my true love gave to me
five gold rings;
four calling birds,
three french hens, two turtle doves
and a partridge in a pear tree.

On
the sixth day of Christmas my true love gave to me
six geese a-laying, five
gold rings;
four calling birds, three french hens, two turtle doves
and a
partridge in a pear tree.

On the seventh day of Christmas my true love
gave to me
seven swans a-swimming,
six geese a-laying, five gold
rings;
four calling birds, three french hens, two turtle doves
and a
partridge in a pear tree.

On the eigth day of Christmas my true love gave
to me
eight maids a-milking, seven swans a-swimming,
six geese a-laying,
five gold rings;
four calling birds, three french hens, two turtle
doves
and a partridge in a pear tree.

On the ninth day of Christmas my
true love gave to me
nine ladies dancing, eight maids a-milking, seven swans
a-swimming,
six geese a-laying, five gold rings;
four calling birds, three
french hens, two turtle doves
and a partridge in a pear tree.

On the
tenth day of Christmas my true love gave to me
ten lords a-leaping,
nine
ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese
a-laying, five gold rings;
four calling birds, three french hens, two turtle
doves
and a partridge in a pear tree.

On the eleventh day of Christmas
my true love gave to me
eleven pipers piping, ten lords a-leaping,
nine
ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese
a-laying, five gold rings;
four calling birds, three french hens, two turtle
doves
and a partridge in a pear tree.

On the twelfth day of Christmas
my true love gave to me
twelve drummers drumming, eleven pipers piping, ten
lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans
a-swimming,
six geese a-laying, five gold rings;
four calling birds, three
french hens, two turtle doves
and a partridge in a pear tree.
press any
key to continue

书上说还要加个版权说明 ^--^

版权 &#169; 1988,Landon Curt Noll
& Larry Bassel。保留所有权利。

历届竞赛源代码都在:http://www.ioccc.org/years.html  (虽然是英文网站 但是很简单,点击作品中.c的文件就直接开始下载源代码了



1.jpg
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-1-20 20:30:30 | 显示全部楼层
。。。。。无语了 发代码会会出现乱码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-1-20 20:35:58 | 显示全部楼层
解决了 ==    代码可用,不过请使用GCC编译器
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-21 12:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表