0%

【趣味】恶臭数字论证器

灵感来源:Github_homo

刷 Github 看到的项目,很有意思,就想着自己写一个。

众所周知,任意一个十进制数都可以拆分成若干个二进制数相加,所以只需要将所有的二的整数次幂用 114514 表示一遍,再将输入的数拆分成二进制数,最后输出即可。此处应该上打表

原理就是这样,下面上大家最喜欢的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;
const int N = 32;
int n, a[N];
bool isFirst = true;
string s[N] = {"", "11/(45-1)*4", "-11+4-5+14", "-11-4+5+14", "11-4+5/1-4", "11-4-5+14", "1*1+45-14", "11*4+5*1*4", "1+1+(4+5)*14", "(114-51)*4+(-11-4+5+14)", "1+1-4+514", "1*(1+4)*51*4+(-11-4+5+14)", "-11+4*514+(11*-4+51-4)", "(1+1)*451*4+(11*(45-1)+4)", "114*5*14+((1+1)*4+51*4)", "1145*14+((11-4)*51-4+(11/(45-1)*4))", "114*51*4+((1+1)*4514+(11*45-14+(11*-4+51-4)))", "114*514+(11*45*14+(-11/4+51/4))", "114514+(1145*14+(1*14+514))", "114514*(-11+4-5+14)+(114*51*4+((1+1)*4514+(11+4*51*4+(11-4*5+14))))", "114514*(-11-4+5+14)+(114*514+(1+14*514+((1+145)*-(1-4)+(11/(45-1)*4))))", "114514*(11-4+5+1-4)+(1145*14+((11+451)*4+(-1-1+4+5*14)))", "114514*(1+1+4*5*1-4)+(114*51*4+(11451+4+(1145+14+(1*-1+45-14))))", "114514*(11+4*5+1+4)+(114*514+(11451+4+(114*-5*(1-4)+(-11+45+1+4))))", "114514*(1*14*5-1+4)+(114*51*4+(114*51+4+(-11+4+5+14)))", "114514*(11+45*-(1-4))+(11*4514+(114*5*14+(1+14+514+(11-4+5+1-4))))", "114514*(11+4*5*14+(-11+4-5+14))+(114*(5-1)*4+(1-14+5+14))", "114514*(114*5+14+(-11+4-5+14))+((1+1)*451*4+(11+45/1-4))", "114514*(1145+14+(1*14-5/1+4))+(1+14*514+(114-5+14))", "114514*(114*5*1*4+(11*4+5*1*4))+(1+14514+(-1-14*(5-14)))", "114514*((1145+1)*4+(114-5-1-4))+(114*51*4+(114*51+4+(11*4*5-14)))", "114514*((1+1)*4514+(11*(45-14)+(11-4+5-1-4)))+(11*4514+(114*5*14+(-(1-14)*5*14+(11-4-5+14))))"};
void print(int x) {
if (isFirst) {
isFirst = false;
} else {
if (s[x][0] != '-') cout << '+';
}
cout << s[x];
}
void BinarySplit(int x) {
for (int i = 30; i >= 0; i--)
if ((1<<i) & x)
print(i+1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
BinarySplit(n);
return 0;
}

该代码只支持拆分 \(1\le n\le 2147483647\) 的数

最后附上原项目链接:恶臭数字论证器,比我写的要强大很多(谁叫人家是 js 呢)