UVA 324 Factorial Frequencies Solution
Solution in c++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
using namespace std;
int main()
{
int n,temp,ar[5000],i,j,c,v,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,t;
while(cin>>n)
{
if(n==0)
break;
a0=a1=a2=a3=a4=a5=a6=a7=a8=a9=0;
ar[0]=1;
c=1;
temp=0;
for(i=1; i<=n; i++)
{
for(j=0; j<c; j++)
{
v=ar[j]*i+temp;
ar[j]=v%10;
temp=v/10;
}
while(temp>0)
{
ar[c]=temp%10;
temp=temp/10;
c++;
}
}
for(i=c-1; i>=0; i--)
{
if(ar[i]==0)
a0++;
else if(ar[i]==1)
a1++;
else if(ar[i]==2)
a2++;
else if(ar[i]==3)
a3++;
else if(ar[i]==4)
a4++;
else if(ar[i]==5)
a5++;
else if(ar[i]==6)
a6++;
else if(ar[i]==7)
a7++;
else if(ar[i]==8)
a8++;
else if(ar[i]==9)
a9++;
}
cout<<n<<"! --"<<endl;
printf(" (0) %d (1) %d (2) %d (3) %d (4) %d\n (5) %d (6) %d (7) %d (8) %d (9) %d\n",a0,a1,a2,a3,a4,a5,a6,a7,a8,a9);
}
}
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
using namespace std;
int main()
{
int n,temp,ar[5000],i,j,c,v,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,t;
while(cin>>n)
{
if(n==0)
break;
a0=a1=a2=a3=a4=a5=a6=a7=a8=a9=0;
ar[0]=1;
c=1;
temp=0;
for(i=1; i<=n; i++)
{
for(j=0; j<c; j++)
{
v=ar[j]*i+temp;
ar[j]=v%10;
temp=v/10;
}
while(temp>0)
{
ar[c]=temp%10;
temp=temp/10;
c++;
}
}
for(i=c-1; i>=0; i--)
{
if(ar[i]==0)
a0++;
else if(ar[i]==1)
a1++;
else if(ar[i]==2)
a2++;
else if(ar[i]==3)
a3++;
else if(ar[i]==4)
a4++;
else if(ar[i]==5)
a5++;
else if(ar[i]==6)
a6++;
else if(ar[i]==7)
a7++;
else if(ar[i]==8)
a8++;
else if(ar[i]==9)
a9++;
}
cout<<n<<"! --"<<endl;
printf(" (0) %d (1) %d (2) %d (3) %d (4) %d\n (5) %d (6) %d (7) %d (8) %d (9) %d\n",a0,a1,a2,a3,a4,a5,a6,a7,a8,a9);
}
}
No comments