首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

觅重复的元素

2012-09-01 
找重复的元素#include iostreamusing namespace stdtemplatetypename T,int indexstruct SumArr{stat

找重复的元素

#include <iostream>using namespace std;template<typename T,int index>struct SumArr{static int GetValue(T* arr){return arr[index] + SumArr<T,index-1>::GetValue(arr);}};template<typename T>struct SumArr<T,0>{static int GetValue(T* arr){return arr[0];}};int main(void){ int arry[11] = {1,2,3,4,5,6,7,8,9,10,2}; printf("%d",SumArr<int,10>::GetValue(arry) - 11*5); getchar();return 0;}

?

?

?

?

热点排行