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!!!

Why wrong?? WA #1
Posted by Alexander 24 Aug 2014 17:31
#include<iostream>
#include<string>

int res;
int Fr(short int nm, short int q)
{
    if((nm-q) == 0) return res;

    if((nm-q)>0)
    {
        res *= nm-q;
        Fr(nm-q,q);
    }
    else
            return res;
}

int main()
{
    short int n=0;    char c;
    int k=0;
    std::string s;
    std::string ss="";
    std::getline(std::cin,s);

    for(int i=0;i<s.length();i++)
    {
        if(isdigit(s[i]))
            ss += s[i];

        if(s[i] == '!') k++;
    }

    int w=1; int temp;
    for(int i=0;i<ss.length();i++)
    {
        for(int j=0;j<(ss.length()-i-1);j++)
            w *= 10;

        if (ss[i] >= '0' && ss[i] <= '9')
            temp = ss[i] - '0';

        n += temp*w;
        w=1;
    }

    res = n;

    printf("%d",Fr(res,k));
}