在網上看到這篇介紹混亂C語言的文章!展示了程序員幽默的一面,細細體會挺有意思的!哈哈,寫在這本身收藏了!(後面是一片實現混亂C的教程,教你如何將本身的代碼寫的本身都看着暈,哈哈哈)程序員
下面的六個程序片斷主要完成這些事情:編程
下面的全部程序均可以在GCC下編譯經過,只有最後一個須要動用C++的編譯器g++才能編程經過。函數
hello1.cspa
#define _________ } #define ________ putchar #define _______ main #define _(a) ________(a); #define ______ _______(){ #define __ ______ _(0x48)_(0x65)_(0x6C)_(0x6C) #define ___ _(0x6F)_(0x2C)_(0x20)_(0x77)_(0x6F) #define ____ _(0x72)_(0x6C)_(0x64)_(0x21) #define _____ __ ___ ____ _________ #include<stdio.h> _____
hello2.c code
#include<stdio.h> main(){ int x=0,y[14],*z=&y;*(z++)=0x48;*(z++)=y[x++]+0x1D; *(z++)=y[x++]+0x07;*(z++)=y[x++]+0x00;*(z++)=y[x++]+0x03; *(z++)=y[x++]-0x43;*(z++)=y[x++]-0x0C;*(z++)=y[x++]+0x57; *(z++)=y[x++]-0x08;*(z++)=y[x++]+0x03;*(z++)=y[x++]-0x06; *(z++)=y[x++]-0x08;*(z++)=y[x++]-0x43;*(z++)=y[x]-0x21; x=*(--z);while(y[x]!=NULL)putchar(y[x++]); }
hello3.c教程
#include<stdio.h> #define __(a) goto a; #define ___(a) putchar(a); #define _(a,b) ___(a) __(b); main() { _:__(t)a:_('r',g)b:_('$',p) c:_('l',f)d:_(' ',s)e:_('a',s) f:_('o',q)g:_('l',h)h:_('d',n) i:_('e',w)j:_('e',x)k:_('\n',z) l:_('H',l)m:_('X',i)n:_('!',k) o:_('z',q)p:_('q',b)q:_(',',d) r:_('i',l)s:_('w',v)t:_('H',j) u:_('a',a)v:_('o',a)w:_(')',k) x:_('l',c)y:_('\t',g)z:___(0x0)}
hello4.c遞歸
int n[]={0x48, 0x65,0x6C,0x6C, 0x6F,0x2C,0x20, 0x77,0x6F,0x72, 0x6C,0x64,0x21, 0x0A,0x00},*m=n; main(n){putchar (*m)!='\0'?main (m++):exit(n++);}
hello5.cci
main(){int i,n[]={(((1<<1)<<(1<<1)<<(1<< 1)<<(1<<(1>>1)))+((1<<1)<<(1<<1))), (((1 <<1)<<(1<<1)<<(1<<1)<<(1<<1))-((1<<1)<<( 1<<1)<<(1<<1))+((1<<1)<<(1<<(1>>1)))+ (1 <<(1>>1))),(((1<<1)<<(1<<1)<<(1<<1)<< (1 <<1))-((1<<1)<<(1<<1)<<(1<<(1>>1)))- ((1 <<1)<<(1<<(1>>1)))),(((1<<1)<<(1<<1)<<(1 <<1)<<(1<<1))-((1<<1)<<(1<<1)<<(1<<(1>>1 )))-((1<<1)<<(1<<(1>>1)))),(((1<<1)<< (1 <<1)<<(1<<1)<<(1<<1))-((1<<1)<<(1<<1)<<( 1<<(1>>1)))-(1<<(1>>1))),(((1<<1)<<(1<<1 )<<(1<<1))+((1<<1)<<(1<<1)<<(1<<(1>>1))) -((1<<1)<<(1<<(1>>1)))),((1<<1)<< (1<<1) <<(1<<1)),(((1<<1)<<(1<<1)<<(1<<1)<<(1<< 1))-((1<<1)<<(1<<1))-(1<<(1>>1))),(((1<< 1)<<(1<<1)<<(1<<1)<<(1<<1))-((1<<1)<< (1 <<1)<<(1<<(1>>1)))-(1<<(1>>1))), (((1<<1 )<<(1<<1)<<(1<<1)<<(1<<1))- ((1<<1)<< (1 <<1)<<(1<<(1>>1)))+(1<<1)), (((1<<1)<< ( 1<<1)<<(1<<1)<< (1<<1))-((1<<1)<< (1<<1) <<(1<<(1>>1)))-((1<<1) <<(1<< (1>>1)))), (((1<<1)<< (1<<1)<<(1<<1)<< (1<<1))- ((1 <<1)<<(1<<1)<<(1<<1))+((1<<1)<< (1<<(1>> 1)))), (((1<<1)<<(1<<1) <<(1<<1))+(1<<(1 >>1))),(((1<<1)<<(1<<1))+((1<<1)<< (1<<( 1>>1))) + (1<< (1>>1)))}; for(i=(1>>1);i <(((1<<1) <<(1<<1))+((1 <<1)<< (1<<(1>>1 ))) + (1<<1)); i++) printf("%c",n[i]); }
hello6.cpp編譯器
下面的程序只能由C++的編譯器編譯(好比:g++)it
#include <stdio.h> #define _(_) putchar(_); int main(void){int i = 0;_( ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ ++++i)_(++++++++++++++++++++ ++++++++++++++++++++++++++++ ++++++++++i)_(++++++++++++++ i)_(--++i)_(++++++i)_(------ ---------------------------- ---------------------------- ---------------------------- ---------------------------- ----------------i)_(-------- ----------------i)_(++++++++ ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++i) _(----------------i)_(++++++ i)_(------------i)_(-------- --------i)_(---------------- ---------------------------- ---------------------------- ---------------------------- ---------------------------- ------i)_(------------------ ---------------------------- i)return i;}
下面是一個Step by Step的教程,教你如何把一個清晰的代碼變得複雜難懂的。固然,這只是一個「簡明教程」了。仍是那句話——「本文僅供朋友們「消遣做樂」,若是你要以爲有意思的話,頂個貼。若是你以爲沒什麼意思的話,一笑了之。僅供娛樂而已,沒必要太過認真。」
下面是一個找出素數的程序:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
void
primes(
int
cap)
{
int
i, j, composite;
for
(i = 2; i < cap; ++i) {
composite = 0;
for
(j = 2; j * j < i; ++j) {
composite += !(i % j);
}
if
(!composite){
printf
(
"%dt"
, i);
}
}
}
int
main()
{
primes(100);
}
|
下面咱們來看看如何把上面這段代碼搞得複雜難懂。
一般來講,for循壞要以while循壞簡單一些,上面的程序有二重for循環,咱們不但要把其變成while循環,並且還要把二重循環的變成一重的循環,而後使用大量的if-else語句來判斷。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
void
primes(
int
cap)
{
int
i, j, composite, t = 0;
while
(t < cap * cap) {
i = t / cap;
j = t++ % cap;
if
(i <= 1);
else
if
(!j)
composite = j;
else
if
(j == i && !composite)
printf
(
"%dt"
,i);
else
if
(j > 1 && j < i)
composite += !(i % j);
}
}
int
main()
{
primes(100);
}
|
遞歸在某些時候是能夠把代碼變得簡單,但大多數的狀況下是把代碼變得複雜,並且很沒有效率。下面是把上面的while循環變成了遞歸。變成了遞歸後,函數的參數都變成3個了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
void
primes(
int
cap,
int
t,
int
composite)
{
int
i,j;
i = t / cap;
j = t % cap;
if
(i <= 1)
primes(cap,t+1,composite);
else
if
(!j)
primes(cap,t+1,j);
else
if
(j == i && !composite)
(
printf
(
"%dt"
,i), primes(cap,t+1,composite));
else
if
(j > 1 && j < i)
primes(cap,t+1, composite + !(i % j));
else
if
(t < cap * cap)
primes(cap,t+1,composite);
}
int
main()
{
primes(100,0,0);
}
|
關於如何弄亂代碼結構,其中一個小技巧是,使用「?」表達式代替if-else語句。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
void
primes(
int
m,
int
t,
int
c)
{
int
i,j;
i = t / m;
j = t % m;
(i <= 1) ? primes(m,t+1,c) : (!j) ? primes(m,t+1,j) : (j == i && !c) ?
(
printf
(
"%dt"
,i), primes(m,t+1,c)) : (j > 1 && j < i) ?
primes(m,t+1,c + !(i % j)) : (t < m * m) ? primes(m,t+1,c) : 0;
}
int
main()
{
primes(100,0,0);
}
|
臨時變量通常用來保存反覆使用的一個表達式的值。使用大量重複的表達式來取消這些臨時變量的也可讓代碼複雜起來。
1
2
3
4
5
6
7
8
9
10
11
12
|
void
primes(
int
m,
int
t,
int
c)
{
((t / m) <= 1) ? primes(m,t+1,c) : !(t % m) ? primes(m,t+1, t % m) :
((t % m)==(t / m) && !c) ? (
printf
(
"%dt"
,(t / m)), primes(m,t+1,c)) :
((t % m)> 1 && (t % m) < (t / m)) ? primes(m,t+1,c + !((t / m) % (t % m))) :
(t < m * m) ? primes(m,t+1,c) : 0;
}
int
main()
{
primes(100,0,0);
}
|
咱們知道,下劃線是合法的變量名,因此,咱們不妨用__,___,____來代替m,t,c。函數名也可使用下劃線來代替。讓咱們來看看求素數的函數能變成什麼。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
void
_(
int
__,
int
___,
int
____)
{
((___ / __) <= 1) ? _(__,___+1,____) : !(___ % __) ? _(__,___+1,___ % __) :
((___ % __)==(___ / __) && !____) ? (
printf
(
"%dt"
,(___ / __)),
_(__,___+1,____)) : ((___ % __) > 1 && (___ % __) < (___ / __)) ?
_(__,___+1,____ + !((___ / __) % (___ % __))) : (___ < __ * __) ?
_(__,___+1,____) : 0;
}
int
main()
{
_(100,0,0);
}
|
在上面的程序中,還有一些常量,你能夠經過增長一個宏定義,或是增長一個函數的形參來取代這一常量。
1
2
3
4
5
6
7
8
9
10
11
12
|
void
_(
int
__,
int
___,
int
____,
int
_____)
{
((___ / __) <= _____) ? _(__,___+_____,____,_____) : !(___ % __) ? _(__,___+_____,___ % __, _____) :
((___ % __)==(___ / __) && !____) ? (
printf
(
"%dt"
,(___ / __)),
_(__,___+_____,____,_____)) : ((___ % __) > _____ && (___ % __) < (___ / __)) ?
_(__,___+_____,____,_____ + !((___ / __) % (___ % __))) : (___ < __ * __) ?
_(__,___+_____,____,_____) : 0;
}
int
main() {
_(100,0,0,1);
}
|
程序到這裏應該差很少了。仍是那句話——「每個程序員都有把源代碼弄複雜的潛質」,你們好自爲之。