Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1761000
  • 博文数量: 100
  • 博客积分: 10122
  • 博客等级: 上将
  • 技术积分: 4092
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-04 20:28
文章分类

全部博文(100)

文章存档

2010年(2)

2009年(28)

2008年(70)

我的朋友

分类: C/C++

2008-04-04 18:35:00

Subject:  deixe-nos jogar o jogo de C programming!
Date:  Thu, 03 Apr 2008 09:10:08 +0100
Mailer:  Evolution 2.12.3 (2.12.3-3.fc8)


Game : Help XiaoMing

XiaoMing is newbie of C programming, recently he wrote a c program to
print 99 '#' sign, as the following :

[code]
int i,n=99;main(){for(i=0;i
[/code]

but apparently this is wrong

Question 1 : please help him to correct this program, but only one of
these kinds of modifications are allowed : 1. delete one character 2.
insert one character 3. change one character

Question 2 : The same restriction ditto, but to output only one '#'

Question 3 : ditto, but to output 100 '#'

correndo!


Miao,

----------------------------

Subject:  Re: deixe-nos jogar o jogo de C programming!
Date:  Thu, 03 Apr 2008 14:48:02 +0100
Mailer:  Evolution 2.12.3 (2.12.3-3.fc8)


Hi all,

Let's reveal the ultimate answer,

$ time perl 2.pl
099# : int i,n=99;main(){for(i=0;i
001# : int i,n=99;main(){for(i=0;i<&n;i--){printf("#");}}
001# : int* i,n=99;main(){for(i=0;i
001# : int *i,n=99;main(){for(i=0;i
001# : int i,*n=99;main(){for(i=0;i
001# : int*i,n=99;main(){for(i=0;i
099# : int i,n=99;main(){for(i=0;i+n;i--){printf("#");}}
099# : int i,n=99;main(){for(i=0;-i
001# : int i,n=99;main(){for(i=0;i
100# : int i,n=99;main(){for(i=0;~i

real    4m9.062s
user    2m45.403s
sys     1m11.831s

099# means the code outputs 99 '#'
001# means the code outputs 1 '#'
100# means the code outputs 100 '#'


The solution here is somehow stupid, we test every possible modified
codes(around 9000 possibilities) and send it to gcc for compiling, and
if it's compilable then we check the output of compiled program.
But we got some intelligent answers and the whole process took only 4
minutes on my laptop :

001# : int i,n=99;main(){for(i=0;i<&n;i--){printf("#");}}
001# : int *i,n=99;main(){for(i=0;i

--

Will we be replaced by HAL from '2001 : A Space Odyssey'?

阅读(2032) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~