1. 程式人生 > >2017/7/31-zznu-oj-問題 B: N! 普拉斯 -【求大數的階乘-ll存不下-然後取尾零的個數輸出-暴力模擬】

2017/7/31-zznu-oj-問題 B: N! 普拉斯 -【求大數的階乘-ll存不下-然後取尾零的個數輸出-暴力模擬】

討論 def ems long size 字符串 problems turn dmi

問題 B: N! 普拉斯

時間限制: 1 Sec 內存限制: 128 MB
提交: 114 解決: 35
[提交] [狀態] [討論版] [命題人:admin]

題目描述

在處理階乘時也需要借助計算器。
在計算機中,數字是通過像01像素矩陣來顯示的,最終的顯示效果如下:
技術分享圖片
寶兒姐一直在思考一個問題,N!末尾究竟有多少個0?我們假設N!末尾有k個0,請按照規則打印k。

輸入

輸入一個正整數n(n< 50) ,輸入以EOF結尾。

輸出

我們假設N!末尾有k個0,請按照規則打印k,數字之間間隔3列0。

樣例輸入

2

樣例輸出

01110
10001
10011
10101
11001
10001
01110

大致思路:

  1、拿上一題的三維字符數組來用,定義也是一致的!

  2、看清題意,尾零的個數不超過兩位數,其實!可以直接特判輸出!

  3、要求輸出時,數字之間間隔3列0,別忘了!

  4、n不大,可以每次把尾零截出來,然後僅保留後十七位——或許不對吧!2333

題解:

技術分享圖片
  1 #include<iostream>
  2 #include<stdio.h>
  3 #include<string.h>
  4 #include<string>
  5 #include<vector>
  6 #include<algorithm>
  7 #define ll long long
  8
using namespace std; 9 #define N 100 10 11 char s1[100]; 12 int sum[100]; 13 vector<int>order; 14 15 char num[12][10][10]={ 16 {"01110","10001","10011","10101","11001", 17 "10001","01110"}, 18 {"00100","01100","00100","00100","00100", 19 "00100","01110"}, 20 {"01110","10001","00001","00110","01000", 21 "10000","11111"
}, 22 {"11111","00001","00010","00110","00001", 23 "10001","01110"}, 24 {"00010","00110","01010","10010","11111", 25 "00010","00010"}, 26 {"11111","10000","10000","11110","00001", 27 "00001","11110"}, 28 {"01111","10000","10000","11110","10001", 29 "10001","01110"}, 30 {"11111","00001","00010","00100","00100", 31 "00100","00100"}, 32 {"01110","10001","10001","01110","10001", 33 "10001","01110"}, 34 {"01110","10001","10001","01111","00001", 35 "00010","11100"}, 36 {"000","000","000","000","000", 37 "000","000"}}; 38 39 void paint( ) //繪制01字符串! 40 { 41 for(int i=0;i<=6;i++){ 42 for(int j=(int)order.size()-1;j>=0;j--){ 43 int x=order[j]; 44 printf("%s",num[x][i]); 45 if(j>0) 46 printf("%s",num[10][i]); 47 } 48 cout<<endl; 49 } 50 } 51 52 int cul(int n){ 53 int len=1; 54 sum[0]=1; 55 for(int i=1;i<=n;i++){ 56 for(int j=0;j<len;j++){ 57 sum[j]*=i; 58 } 59 int j=0; 60 while(j<len){ 61 if(sum[j]>=10){ 62 sum[j+1]+=sum[j]/10; 63 sum[j]%=10; 64 if(j+1>=len) 65 len++; 66 } 67 j++; 68 } 69 } 70 return len; 71 } 72 73 int main() 74 { 75 int n; 76 while(scanf("%d",&n)!=EOF){ 77 78 memset(sum,0,sizeof(sum)); 79 int len3=cul(n); //計算n的階乘! 80 81 /* for(int i=0;i<len3;i++){ 82 printf("%d",sum[i]); 83 } 84 cout<<"*****"<<endl; 85 */ 86 int i=0; 87 while(sum[i]==0) //計算開頭的零的數量!! 88 i++; 89 90 order.clear(); 91 if(i==0) 92 order.push_back(0); 93 while(i>0){ 94 order.push_back(i%10); 95 i/=10; 96 } 97 98 paint(); 99 } 100 101 102 return 0; 103 }
View Code(暴力模擬題,一定要耐住性子,不急不躁,穩住才能AC)

2017/7/31-zznu-oj-問題 B: N! 普拉斯 -【求大數的階乘-ll存不下-然後取尾零的個數輸出-暴力模擬】