求1+2+…+n, 要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)。
摘要:
方法一:利用构造函数和静态数据成员[cpp]view plaincopy#include<iostream>usingnamespacestd;classTemp{public:Temp(){++N;Sum+=N;}staticvoidReset(){N=0;Sum=0;}staticintGetSum(){returnSum;}private:staticintN;staticintSum;};intTemp::N=0;intTemp::Sum=0;intsolution_Sum(intn){Temp::Reset();Temp*a=newTemp[n];delete[]a;a= 阅读全文
posted @ 2013-04-22 19:37 lzm风雨无阻 阅读(3999) 评论(1) 推荐(3)
浙公网安备 33010602011771号