可以在程序输出其自身的副本 [英] Can a program output a copy of itself

查看:128
本文介绍了可以在程序输出其自身的副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这可能是一个经典的问题,但我不知道答案的。可以在程序的输出自身的副本,并且,如果是的话,有没有做这样的短节目?

I think this might be a classic question but I am not aware of an answer. Can a program output a copy of itself, and, if so, is there a short program that does this?

我不接受空计划作为一个答案,我不接受访问有自己的源$ C ​​$ C程序。相反,我想是这样的:

I do not accept the "empty program" as an answer, and I do not accept programs that have access to there own source code. Rather, I am thinking something like this:

int main(int argc, char** argv){ printf("int main(argc, char** argv){ printf...

但我不知道该怎么继续......

but I do not know how to continue...

推荐答案

最基内斯的基本思路是:

The basic idea of most quines is:

  1. 您写的code,它接受一个字符串取值并打印出来,而更换事件(或的发生)在取值特殊子的的按价值的取值本身。

  1. You write code that takes a string literal s and prints it, while replacing occurrences (or the occurrence) of a special substring foo in s by the value of s itself.

您走程序的整个源$ C ​​$ C,到目前为止,并用它作为定义取值。但您排除定义 取值 从字符串,而是通过替换它的

You take the entire source code of the program so far and use it as the definition for s. but you exclude the definition of s from the string, instead replacing it by foo.

嗯,这是一般的想法。剩下的就是字符串格式化的细节,真的。

Well, that's the general idea. The rest is string formatting details, really.

这篇关于可以在程序输出其自身的副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆