问题 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 }
(暴力模拟题,一定要耐住性子,不急不躁,稳住才能AC)
原文地址:https://www.cnblogs.com/zhazhaacmer/p/9399455.html
时间: 2024-10-07 20:42:21