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 }
原文:https://www.cnblogs.com/butchert/p/11922147.html