跳到正文

LuanSheGe

817742

My name is Van. I'm an artist. I'm a permance artist. I'm hired for people to fulfill their fantacies. The deep dark fantacies.

在洛谷打开
资料、奖项与版本

资料

编号
817742
抓取

抽象大师速成

  • 任务

求出数组a中偶数的个数

正常代码:


C
#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]的

再加上一些废话,扰乱视线:


C
#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:


C
#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;
} 

已经非常抽象了

但我们还可以:


C
#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的死循环 所以可以改成这样子:


C
#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;
} 

大功告成

还没有收录这位用户的文章。