oracle的 C/C++ 面试题, 大家来挑战一下吧.
打印 1--1000;
不能使用条件运算符.
不能使用循环语句.
Task:
Print numbers from 1 to 1000 without using any loop or conditional statements. Don't just write the printf() or cout statement 1000 times.
[解决办法]
与这一题思想类似
http://zhedahht.blog.163.com/blog/static/2541117420072915131422/
Oracle也堕落了,哥就不信他们敢在产品里写这种代码
[解决办法]
这是因为你沉迷在这些无聊的东西里了,还不理解算法和架构的决定性力量。
这些小技巧真心无聊,无用。
#include<iostream>using namespace std;class print{public: print(){ num++; cout << num <<endl; }private: static int num;};int print::num = 0;int main(){ new print[1000]; return 0;}
[解决办法]
#include<iostream>using namespace std;class print{public: print(){ num++; cout << num <<endl; }private: static int num;};int print::num = 0;int main(){ print *pt=new print[1000]; delete [] pt; pt = NULL; return 0;}
[解决办法]
void print(){ static int i = 1; (i - 1001) && (printf("%d ", i++)) && (print(), 0);}