首页 > 其他分享 >Quine

Quine

时间:2023-02-26 00:11:40浏览次数:56  
标签:defchar const format char print defstr Quine

cpp:

#include <bits/stdc++.h>
const char a = '\n', b = '"', c = '\\', d = '\t';
const char *s1 = "#include <bits/stdc++.h>%c";
const char *s2 = "const char a = '%cn', b = '%c', c = '%c%c', d = '%ct';%c";
const char *s3 = "const char *s%d = %c%s%c;%c";
const char *s4 = "int main() {%c%cprintf(s1, a);%c";
const char *s5 = "%cprintf(s2, c, b, c, c, c, a);%c";
const char *s6 = "%cprintf(s3, %d, b, s%d, b, a);%c";
const char *s7 = "%cprintf(s4, a, d, a), printf(s5, d, a);%c";
const char *s8 = "%cfor(int i = 1; i <= 10; ++i) printf(s6, d, i, i, a);%c";
const char *s9 = "%cprintf(s7, d, a), printf(s8, d, a), printf(s9, d, a);%c";
const char *s10 = "%creturn !printf(s10, d, a);%c}";
int main() {
	printf(s1, a);
	printf(s2, c, b, c, c, c, a);
	printf(s3, 1, b, s1, b, a);
	printf(s3, 2, b, s2, b, a);
	printf(s3, 3, b, s3, b, a);
	printf(s3, 4, b, s4, b, a);
	printf(s3, 5, b, s5, b, a);
	printf(s3, 6, b, s6, b, a);
	printf(s3, 7, b, s7, b, a);
	printf(s3, 8, b, s8, b, a);
	printf(s3, 9, b, s9, b, a);
	printf(s3, 10, b, s10, b, a);
	printf(s4, a, d, a), printf(s5, d, a);
	for(int i = 1; i <= 10; ++i) printf(s6, d, i, i, a);
	printf(s7, d, a), printf(s8, d, a), printf(s9, d, a);
	return !printf(s10, d, a);
}

python:

a = '"'
defchar = """{0} = '{1}'"""
defstr = """{0} = {1}{1}{1}{2}{1}{1}{1}"""
body = """print(defchar.format({0}a{0}, a))
print(defstr.format({0}defchar{0}, a, defchar))
print(defstr.format({0}defstr{0}, a, defstr))
print(defstr.format({0}body{0}, a, body))
print(body.format(a))"""
print(defchar.format("a", a))
print(defstr.format("defchar", a, defchar))
print(defstr.format("defstr", a, defstr))
print(defstr.format("body", a, body))
print(body.format(a))

zip:
Quine.zip

print 0
print 2
print 0
print 2
print 0
repeat 3 2
print 2
repeat 3 2
print 2
repeat 3 2

标签:defchar,const,format,char,print,defstr,Quine
From: https://www.cnblogs.com/JerryTcl/p/17155755.html

相关文章