Google考试题:定义控制台应用程序的入口点《节选自froster.>

 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
11 using   namespace  std;
12 unsigned  long  count  =   0 ;
13 unsigned  long  F( int  buf[],  int  start );
14 unsigned  long  T[ 20 ];
15
16 void  CaculateT( void )
17 ExpandedBlockStart.gifContractedBlock.gif {
18    int i;
19    T[1= 1;
20
21    for(i=2;i<10;i++)
22ExpandedSubBlockStart.gifContractedSubBlock.gif    {
23        T[i] = pow(10,(i-1)) + 10 * T[i-1];
24    }

25}

26
27 int  _tmain( int  argc, _TCHAR *  argv[])
28 ExpandedBlockStart.gifContractedBlock.gif {
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
38ExpandedSubBlockStart.gifContractedSubBlock.gif    {
39        i=1;
40        temp = M;
41        while( temp > 0 )
42ExpandedSubBlockStart.gifContractedSubBlock.gif        {
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
64 unsigned  long  F( int  buf[],  int  start)
65 ExpandedBlockStart.gifContractedBlock.gif {
66
67    unsigned long temp = 0;
68    if(start==1)
69ExpandedSubBlockStart.gifContractedSubBlock.gif    {
70        if(buf[start] == 0)
71            return 0;
72        else
73            return 1;
74    }

75
76    if( buf[start] == 1)
77ExpandedSubBlockStart.gifContractedSubBlock.gif    {
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)
85ExpandedSubBlockStart.gifContractedSubBlock.gif    {
86        return F(buf, start - 1);
87    }

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

92
93}

转载于:https://www.cnblogs.com/gredswsh/archive/2010/09/16/1827953.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值