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

What's Wrong with my answer?WA test#10..It works absolutely perfectly in my computer & all conditions are fulfilled
Posted by Scaletta_Z 5 Apr 2018 15:43
using namespace std;
#include<iostream>
#include<string>
#include<sstream>
#include<ctype.h>
void factorial(unsigned long n,unsigned long k);
int main()
{
    unsigned long counter=0;
    string s;
    unsigned long n;

    while(getline(cin,s))
    {
    counter=0;
    string::size_type position,position2;
    position=s.find(' ');
    string num;
    for(int i=0;i<position;i++)
    {
        if(isdigit(s[i]))
            num+=s[i];

    }
    stringstream ss(num);
    ss>>n;
    position2=s.find('!');
    if(position2==position+1)
    {
       for(int i=position+1;i<s.size();i++)
        if(s[i]=='!')
        counter++;
   factorial(n,counter);
    }

    }
}

void factorial(unsigned long n,unsigned long k)
{
  unsigned long res=1;
  int mod=n%k;
  unsigned long mul=n;
    if(mod!=0)
    {
        while(mul>1)
        {
            res*=mul;
            mul=mul-k;
        }
        cout<<res<<endl;
    }
    else
    {
        while(mul>=k)
        {
            res*=mul;
            mul=mul-k;
        }
        cout<<res<<endl;
    }
}

Edited by author 05.04.2018 15:46

Edited by author 05.04.2018 15:47