求解题1和2小题

【图文】1和2章小结例题_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
1和2章小结例题
大小:143.00KB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢1036人阅读
算法(70)
被考倒了。。。
基本答案来自
用到了:类的静态变量特性,Bool的二值特性,模板元编程!!!,还有就是我的 霸王硬上弓 算法
//============================================================================
: IntrestingAdd.cpp
// Version
// Copyright
: Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include &iostream&
int f(int n);
int b(int n);
//**********************方法一:利用类静态变量*****************
class Value{
static void initValue(){
n++;
sum +=
static int getValue(){
int Value::n = 0;
int Value::sum = 0;
//******************方法二,利用模板元编程********************************
template&int N&
struct add{
enum {result = N + add&N-1&::result};
template&&
struct add&0&
enum {result=0};
//***********************方法三:利用Bool类型只有01值!!!
int f2(int);
int main() {
cout&&&1+2+..+100=&&&f2(100)&&//f(100);
cout&&add&100&::result&&
Value::initValue();
Value* temp = new Value[100];
cout&&Value::getValue();
//******************本想用递归,结果。。。还是用到了if,不过改进下 成为f2()********************************
int f(int n){
if(n == 1)
int sum = 0;
sum = n + f(n-1);
int f2(int n){
int arr[2];
arr[0] = 0;
arr[1] = f(n-1);
return n + arr[!!n];
//***************************方法4:你妹的,老子强奸了你 哈哈哈
10*10*************
int b(int n){
return n + n+1 + n+2 + n+3 + n+4 + n+5 + n+6 + n+7 + n+8 + n+9;
return b(1) + b(11) + b(21) + b(31) + b(41) + b(51) + b(61) + b(71) + b(81) + b(91);
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:129418次
积分:2605
积分:2605
排名:第13898名
原创:132篇
转载:20篇
(1)(1)(1)(1)(1)(2)(3)(2)(5)(3)(3)(5)(36)(89)}

我要回帖

更多关于 求解题 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信