比这篇新的文章: list转为一组tuple的方法
比这篇旧的文章: template meta test

题目:编程计算从1到2008080808之间的整数有多少个含有数字7

语言: C++, 标签: 无  2008/08/23发布 2个月前更新
作者: xpycc, 点击274次, 评论(0), 收藏者(0)

开关行号, 全选(Ctrl+C复制) | 一键复制:HTML, BBCode(Discuz!) , 源代码 | 查看:裸代码, 全屏
背景
主题: 字体:
C++语言: 题目:编程计算从1到2008080808之间的整数有多少个含有数字7
01 #include    <iostream>
02
03 using namespace std;
04 const int MAX = 2008080808;
05 const int IT = 7;
06
07 template<int n, int curr, int last, int base, int weight>
08 class A
09 {
10     enum{it = n/base%10};
11 public:
12     enum{result = A<n, (it-(it>IT))* weight+((it<IT)?curr:(it==IT?last:base+curr)), last+base*it, base*10, (weight?weight*9+base:1)> :: result};
13 };
14
15 template<int n, int curr, int base, int weight>
16 class A<n, curr, n, base, weight>
17 {
18 public:
19     enum {result = curr};
20 };
21
22 int main(int argc, char* argv[])
23 {
24     cout << A<MAX+1, 0, 0, 1, 0>:: result << endl;
25     return 0;
26 }
打分:

所有评论,共0条:( 我也来说两句)


发表评论

注册登录后再发表评论