以文本方式查看主题

-  趣题之家  (http://www.qthome.org/bbs/index.asp)
--  奇异题目  (http://www.qthome.org/bbs/list.asp?boardid=5)
----  输出你自己的代码(一道有难度的问题)  (http://www.qthome.org/bbs/dispbbs.asp?boardid=5&id=184)

--  作者:whqlsc
--  发布时间:11/2/2004 2:02:20 PM

--  输出你自己的代码(一道有难度的问题)
Problem

你曾经看到过这样的程序吗?当它运行的时候,将会输出一些字符,这些字符恰好组成了这个程序的代码本身。

请你写这样的一个程序。

请注意,你的程序运行时将不能访问到源程序(系统已经将源代码删除)。
Input

本题没有输入数据。
Output

输出必须和你提交的代码本身一致



--  作者:ppatsname
--  发布时间:11/5/2004 12:12:45 PM

--  
空白就好了。。。。
--  作者:欢乐
--  发布时间:11/5/2004 8:07:51 PM

--  
好问题。我喜欢这样的
--  作者:逍遥婵娟
--  发布时间:11/6/2004 10:27:49 PM

--  
源程序为“对不可编译的错误代码提示”
--  作者:欢乐
--  发布时间:11/7/2004 1:35:44 PM

--  

……正解……


--  作者:McDsl
--  发布时间:1/28/2005 7:14:40 PM

--  
tju上面有现题
--  作者:趣题之主
--  发布时间:1/31/2005 6:34:48 PM

--  

这题到现在我还没有AC……


--  作者:雪儿
--  发布时间:2/9/2005 5:56:06 PM

--  

--  作者:doubleelec
--  发布时间:3/3/2005 10:51:02 AM

--  
以下是引用逍遥婵娟在2004-11-6 22:27:49的发言:
源程序为“对不可编译的错误代码提示”


不懂。不可编译怎么“运行”?
--  作者:doubleelec
--  发布时间:3/3/2005 4:13:41 PM

--  

这是一个linux下编的程序,将源代码命名为 prnself.s ,用gcc编译


gcc -o prnself prnself.s


然后删除prnself.s,运行


./prnself


试试看。



.LC0:
.incbin "prnself.s"
.LC1:
.string "%c"
.globl main
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $.LC0, -4(%ebp)
.L2:
cmpl $.LC1, -4(%ebp)
jb .L5
jmp .L3
.L5:
subl $8, %esp
movl -4(%ebp), %eax
movsbl (%eax),%eax
pushl %eax
pushl $.LC1
call printf
addl $16, %esp
leal -4(%ebp), %eax
incl (%eax)
jmp .L2
.L3:
movl $0, %eax
leave
ret



[此贴子已经被作者于2005-3-4 10:14:24编辑过]

--  作者:doubleelec
--  发布时间:3/4/2005 10:15:58 AM

--  

C语言程序:


char *s="int main() { char *p;    putchar(\'c\');putchar(\'h\');putchar(\'a\');putchar(\'r\');putchar(\' \');putchar(\'*\');putchar(\'s\');putchar(\'=\');putchar(34);    for (p=s; *p; p++) putchar(*p); putchar(34);putchar(\';\');putchar(10);    for (p=s; *p; p++) putchar(*p);    putchar(10);    return 0; }";
int main() { char *p;    putchar(\'c\');putchar(\'h\');putchar(\'a\');putchar(\'r\');putchar(\' \');putchar(\'*\');putchar(\'s\');putchar(\'=\');putchar(34);    for (p=s; *p; p++) putchar(*p); putchar(34);putchar(\';\');putchar(10);    for (p=s; *p; p++) putchar(*p);    putchar(10);    return 0; }


[此贴子已经被作者于2005-3-4 11:28:30编辑过]

--  作者:doubleelec
--  发布时间:3/4/2005 11:27:15 AM

--  

格式弄得好看一点:


char *str="int main()\\n"
"{\\n"
" char *p;\\n"
"\\n"
" printf(\\"char *str=%c\\", 34);\\n"
" for (p=str; *p; p++) {\\n"
"  if (*p == 34)\\n"
"   printf(\\"%c%c\\", 92, *p);\\n"
"  else if (*p == 10)\\n"
"   printf(\\"%cn%c%c%c\\", 92, 34, 10, 34);\\n"
"  else\\n"
"   putchar(*p);\\n"
" }\\n"
" printf(\\"%c%c%c%c%s%c\\", 34, 59, 10, 10, str, 10);\\n"
"\\n"
" return 0;\\n"
"}";


int main()
{
char *p;


printf("char *str=%c", 34);
for (p=str; *p; p++) {
  if (*p == 34)
   printf("%c%c", 92, *p);
  else if (*p == 10)
   printf("%cn%c%c%c", 92, 34, 10, 34);
  else
   putchar(*p);
}
printf("%c%c%c%c%s%c", 34, 59, 10, 10, str, 10);


return 0;
}



[此贴子已经被作者于2005-3-4 11:29:10编辑过]

--  作者:gdgzgq
--  发布时间:3/4/2005 8:15:27 PM

--  
如果用PASCAL,怎么编?


网上贸易 创造奇迹! 阿里巴巴 Alibaba

Powered By Dvbbs Version 7.1.0
Copyright ©2003 - 2006 QTHome.Org
页面执行时间 00.12109 秒, 3 次数据查询
本论坛采用阿里巴巴支付宝网上银行支付系统,安全、可靠、便捷