首页 > 其他 > 详细

2的任意次方,并输出运算时间

时间:2019-11-24 14:08:03      阅读:107      评论:0      收藏:0      [点我收藏+]
 1 // ConsoleApplication3.cpp : 定义控制台应用程序的入口点。
 2 //
 3 
 4 #include "stdafx.h"
 5 #include"windows.h"
 6 #include"iostream"
 7 using namespace std;
 8 
 9 #define MAX 100000
10 
11 int main()
12 {
13     int a[MAX] = { 0 },n=0;
14     a[MAX-1] = 1;
15     SYSTEMTIME st;
16 
17     cout << "Input n:" << endl;
18         cin>> n;
19 
20         GetLocalTime(&st);
21         int m11= st.wMinute;
22         int n11 = st.wSecond;
23 
24     for (int i = 0; i < n; i++)
25     {
26         int j = MAX-1;
27         for (j = MAX-1; j >= 0; j--)
28             a[j] = a[j] * 2;
29 
30         for(j=MAX-1;j>=0;j--)
31         {
32             if (a[j] >= 10)
33             {
34                 a[j] = a[j] % 10;
35                 a[j - 1] = a[j - 1] + 1;
36             }
37         }
38     }
39 
40     for (int i = 0; i < MAX;  i++)
41     {
42         if (a[i] != 0)
43         {
44             int n = 0;
45             for (int j = i; j <MAX; j++)
46             {
47                 cout << a[j] << "  ";
48                 if ((n + 1) % 5 == 0)
49                     cout << "     ";
50                 if ((n + 1) % 10 == 0)
51                     cout << endl;
52                 n++;
53             }
54             cout << endl;
55             cout << "共有" << MAX - i << "" << endl;
56             break;
57         }
58     }
59 
60     GetLocalTime(&st);
61     int m1 = st.wMinute;
62     int n1 = st.wSecond;
63 
64 
65     cout << "Total time:"<<(m1 - m11) * 60 + (n1 - n11) << endl;
66     
67     cout << endl;
68 
69     return 0;
70 }

 

2的任意次方,并输出运算时间

原文:https://www.cnblogs.com/butchert/p/11922147.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!