UVa 324 - Factorial Frequencies


 * 1) include
 * 2) include
 * 3) include 
 * 4) include 
 * 5) include 
 * 6) include 

using namespace std;

int socantinh,dodaitam,hang; int boso[15]; int k,tam1[800],tam2[800],kq[1600]; int giaithua[800][1600];

void resetso(int a[]) {	int j;	for(j=0;j<11;j++) a[j]=0; }

void reset(int a[]) {	int j;	for(j=0;j<1600;j++) a[j]=0; }

void daochuoi(char n[]) {	int j,tg,dodai; dodai=strlen(n); for(j=0;j<=dodai/2;j++) {		tg=n[j]; n[j]=n[dodai-1-j]; n[dodai-1-j]=tg; } }

void nhan(int a[],int b[],int ketqua[],int dai1,int dai2) {	int i,j; dodaitam=dai2; for(i=0;i=0;i--) if(b[i]!=0) return i+1; }

void gan1(int a[1600],int b[],int dai1) {	int i;	for(i=0;i0) dd1=1; if(so>9 && so<100) dd1=2; if(so>99 && so<1000) dd1=3; dao(so,tam1,dd1); dd2=dodaichuoi(tam2); nhan(tam1,tam2,kq,dd1,dd2); gan1(kq,tam2,dodaitam); gan2(kq,giaithua,so,dodaitam); reset(kq); } }

void dem(int so0) {	int i,dai; for(i=1600;i>=0;i--) {		if(giaithua[so0-1][i]!=0) {			dai=i+1; break; }	}	for(i=0;i<dai;i++) boso[giaithua[so0-1][i]]++; }

void output {	printf("%d! --\n",socantinh); printf("  (0)%5d    (1)%5d    (2)%5d    (3)%5d    (4)%5d\n",boso[0],boso[1],boso[2],boso[3],boso[4]); printf("  (5)%5d    (6)%5d    (7)%5d    (8)%5d    (9)%5d\n",boso[5],boso[6],boso[7],boso[8],boso[9]); }

void out2 {	int x=1; int y=0; printf("%d! --\n",socantinh); printf("  (0)%5d    (1)%5d    (2)%5d    (3)%5d    (4)%5d\n",y,x,y,y,y); printf("  (5)%5d    (6)%5d    (7)%5d    (8)%5d    (9)%5d\n",y,y,y,y,y); }

int main {	//freopen("324.inp","r",stdin); //freopen("324.out","w",stdout); tinhgt; while(scanf("%d",&socantinh)>0 && socantinh!=0) {		if(socantinh>0) {			if(socantinh<=3) {				if(socantinh==1) boso[1]++; if(socantinh==2) boso[2]++; if(socantinh==3) boso[6]++; }			else dem(socantinh); output; resetso(boso); }		else {			out2; }	}		return 0; }