zzEMC笔试题目--BT递归

本站内容除转载精华分类或注明zz以外,其他均为原创内容。转载请注明出处,yhustc.com版权所有

要求是只用一条语句(函数体就一个分号)完成功能。要求:
不能有逗号,不能有新变量声明,不能用?:,不能用循环,不能用char int 什么什么的保留字符

cpp代码
  1. #include "stdafx.h"  
  2. #include <iostream>   
  3. #include <cstring>  
  4.  
  5. using namespace std;  
  6. /*  
  7.     函数声明如下  
  8.  
  9. int func(int i ,int N);  
  10.  
  11. 其中i <= N,功能输出i递增到N再递减到i的整数,每行输出一个数。比如func(1,5)就是  
  12. */ 
  13.  
  14. int func(int i,int N)  
  15. {  
  16.     return ((i==N&&printf("%d\n",i))||(printf("%d\n",i)&&func(i+1,N)&&printf("%d\n",i+1)));  
  17. }  
  18.  
  19. void main()  
  20. {  
  21.     cout<<func(1,5)<<endl;       
  22.     getchar();  

本贴地址:http://bbs.yingjiesheng.com/thread-231378-1-1.htm

Tags:


1 Responses to “zzEMC笔试题目--BT递归”

  1. Lin.x  | 2009-11-02 12:49:10

    很变态...
    链接应为
    http://bbs.yingjiesheng.com/thread-231378-1-1.html

发表评论