/*
46:> 求和1+2+3+....n
不能使用for while if else switch case 三目运算符
*/
class Sum
{
public:
Sum()
{
++N;
sum += N;
}
static void set()
{
N = 0;
sum = 0;
}
static int GetSum()
{
return sum;
}
private:
static size_t N;
static size_t sum;
};
size_t Sum::N = 0;
size_t Sum::sum = 0;
int GetTotal(size_t n)
{
Sum::set();
Sum *tmp = new Sum[100];
delete []tmp;
tmp = NULL;
return Sum::GetSum();
}
[剑指offer]求和1+2+3+....n
最新推荐文章于 2022-11-13 20:57:01 发布