zzEMC笔试题目--BT递归

要求是只用一条语句(函数体就一个分号)完成功能。要求:
不能有逗号,不能有新变量声明,不能用?:,不能用循环,不能用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:
上一篇: 家里居然可以用IPv6了
下一篇: zz传腾讯数百万一次性买断“开心农场”

相关日志推荐

1 条留言

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

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

发表评论

  
  
   (点击图片更换验证码)
点击刷新验证码