ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1083. Factorials!!!

LOOK AT THIS IT'S TRUE
Posted by khashayar 31 Aug 2008 22:56
#include <iostream>
using namespace std;
int a,b,i,d,j=2,e=1;
char c[25];
int mod(int d,int f){
if(d<=f){return d;}
else{return mod(d-f,f);}
}
int fac(int g,int h){
if(g==d){return d;}
else{return e*g*fac(g-h,h);}
}
int main(){
gets(c);
a=c[0]-48;
if(c[1]=='0'){
a=10;
j=3;
}
for (i=j;c[i]=='!';i++){
b++;
}
d=mod(a,b);
cout<<fac(a,b);
return 0;}
Re: LOOK AT THIS IT'S TRUE
Posted by bsu.mmf.team 13 Sep 2008 23:35
#include <iostream>


using namespace std;

int count (char u[],char p)
{
    int k=0;
    for (int i=0; i<strlen(u); i++)
    if (u[i]==p) k++;
    return k;
}

int main ()
{
    int N,k=0,sum; cin>>N;
    char S[20],t='!';
    gets(S);
    sum=N;
    while (N>=count(S,t))
    {
        N-=count(S,t);
        if (N)
        sum*=N;
    }
    cout<<sum;
    return 0;
}

Another variation )))

Edited by author 13.09.2008 23:35