抽象大师速成
-
任务
求出数组a中偶数的个数
正常代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[]={1,2,3,4,5},ans=0;
for(int i=0;i<5;i++)if(a[i]%2==0)ans++;
return 0;
} 但其实a[i]是可以写成i[a]的
再加上一些废话,扰乱视线:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[]={1,2,3,4,5},ans=0;
for(int i=0;i<5;i++)if(!(*&(i-1)[a+1]%2))ans++;
return 0;
} 紧接着
我们还可以写一个飞舞函数O.o:
#include<bits/stdc++.h>
struct ZDJD{
bool o(int x){
return x ? true : false;
}
}O;
int main()
{
int a[]={1,2,3,4,5},ans=0;
for(int i=0;i<5;i++)if(O.o(!(*&(i-1)[a+1]%2)))ans++;
return 0;
} 已经非常抽象了
但我们还可以:
#include<bits/stdc++.h>
#define false true
#define true false
struct ZDJD{
bool o(int x){
return x ? false : true;
}
}O;
int main()
{
int a[]={1,2,3,4,5},ans=0;
for(int i=0;i<5;i++)if(O.o(!(*&(i-1)[a+1]%2)))ans++;
return 0;
} 疯狂的宏定义
但其实这样是会编译错误的
程序会陷入false到true的死循环 所以可以改成这样子:
#include<bits/stdc++.h>
#define false 1
#define true 0
struct ZDJD{
bool o(int x){
return x ? true : false;
}
}O;
int main()
{
int a[]={1,2,3,4,5},ans=0;
for(int i=0;i<5;i++)if(O.o(!(*&(i-1)[a+1]%2)))ans++;
return 0;
}