zoukankan      html  css  js  c++  java
  • 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
    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}
  • 相关阅读:
    转载Typora学习笔记
    SpringMVC整体接受前台参数
    基于SSM框架实现oa项目
    Don't know how to iterate over supplied "items" in &lt;forEach&gt;
    springMVC自定义类型转换器(date类型转换)
    springMVC异常处理
    linux服务器基础运维
    什么是服务器
    mysql binlog日志 恢复数据,mysqldump备份
    nginx LVS Haproxy
  • 原文地址:https://www.cnblogs.com/gredswsh/p/1827953.html
Copyright © 2011-2022 走看看