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

wrong answer test #15
Posted by Ravi Maggon 21 Aug 2010 11:31
can anyone tell me whats wrong with my code. it displays wrong answer test #15

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    long int n;
    long int ans=1;
    char k[20];
    cin>>n>>k;
    if(n<1||n>10)
                 return 0;
    long int res;
    res=n%strlen(k);
    long int i=0,length=strlen(k);
    if(length<1||length>20)
           return 0;

    if(res==0)
    {
        while(n-i*length>=length)
        {
                       ans=ans*(n-i*length);
                       i++;
        }
    }
    else
    {
        while(n>=i*length)
        {
                       ans=ans*(n-i*length);
                       i++;
        }
    }
    cout<<ans;
    return 0;
}

Edited by author 21.08.2010 11:32
Re: wrong answer test #15
Posted by TheDreamCatcher 4 Dec 2010 14:18
15 test
n=10
k=20

it's last test
Re: wrong answer test #15
Posted by Rainsoul 15 Feb 2011 22:13
> char k[20]
You forgot about the null character ( '\0' ). Correct is
char k[21]