MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Tuesday, March 5, 2013

uva problem 10323


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <math.h>
#include<string.h>
#include<stdio.h>
using namespace std;

#define DEBUG
#define REP(i,a) for(i=0;i<a;i++)
#define FOR(i,a,b) for(i=a;i<b;i++)
#define VE vector<int>
#define SZ size()
#define PB push_back
char *fac[1005]={0};
void factorial()
{
    fac[0]="1";
fac[1]="1";
int l1=strlen(fac[0]);
int l2=strlen(fac[1]);
int l;
for(long i=2;i<=1002;i++)
{
char str[10000];
l=strlen(fac[i-1]);
long q,T,ca;
    T=0;ca=0;
    for(q=l-1;q>=0;q--)
    {

     int ans=0;
       ans=(fac[i-1][q]-48)*i+ca;
       str[T]=ans%10+48;
       ca=ans/10;
       T++;
    }
    while(ca>0)
    {
      str[T]=ca%10+48;
       ca=ca/10;
      T++;
    }


  str[T]='\0';
  fac[i]=new char[T+1];
   long y=0;
     for(long x=T-1;x>=0;x--,y++)
           fac[i][y]=str[x];
        fac[i][y]='\0';

}
}
int main()
{

int n;
factorial();
while(scanf("%d",&n)!=EOF)
{
  printf("%d!\n",n);
  printf("%s\n",fac[n]);
 // printf("%d\n",strlen(fac[n]));
}
return 0;
}

No comments:

Post a Comment