随笔 - 1  文章 - 0  trackbacks - 0
<2005年12月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿

随笔档案

搜索

  •  

最新评论

 

 1// MyCountOne.cpp : 定义控制台应用程序的入口点。
 2//
 3
 4#include "stdafx.h"
 5#include <iostream>
 6#include <string>
 7#include <math.h>
 8#include <windows.h>
 9#include <ctime>
10
11using namespace std;
12unsigned long count = 0;
13unsigned long F(int buf[], int start );
14unsigned long T[20];
15
16void CaculateT(void)
17{
18    int i;
19    T[1= 1;
20
21    for(i=2;i<10;i++)
22    {
23        T[i] = pow(10,(i-1)) + 10 * T[i-1];
24    }

25}

26
27int _tmain(int argc, _TCHAR* argv[])
28{
29    unsigned long temp, M = 199900;
30    int i;
31    int buf[20];
32    DWORD start, end, usetime;
33    start = GetTickCount();
34    
35    CaculateT();
36
37    do
38    {
39        i=1;
40        temp = M;
41        while( temp > 0 )
42        {
43            buf[i++= temp % 10;
44            temp /= 10;
45        }

46
47        cout<<M<<"->"<<F(buf, i-1)<<"  ";
48        if(M%5==0
49            cout<<endl;
50    }
while(M++<199981);
51
52    end = GetTickCount();
53    usetime = start - end;
54    cout<<"use "<<usetime<<"milliseconds"<<endl;
55
56    cout<<M-1;
57
58
59    return 0;
60
61
62}

63
64unsigned long F(int buf[], int start)
65{
66
67    unsigned long temp = 0;
68    if(start==1)
69    {
70        if(buf[start] == 0)
71            return 0;
72        else
73            return 1;
74    }

75
76    if( buf[start] == 1)
77    {
78        temp = 0;
79        for(int i=start-1; i>0; i--)
80            temp = temp * 10 + buf[i];
81
82        return ( T[start-1+ temp + 1 + F(buf, start - 1) );
83    }

84    else if(buf[start] == 0)
85    {
86        return F(buf, start - 1);
87    }

88    else
89    {
90        return ( buf[start] * T[start-1+ pow(10, start - 1+ F(buf, start - 1) );
91    }

92
93}
posted on 2005-12-04 12:16 froster 阅读(230) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理