324 - Factorial Frequencies

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Mon Oct 30, 2006 8:40 pm

Dont open a new thread if there is one already. Check the i/o set

Input:

Code: Select all

273
0
Output:

Code: Select all

273! --
   (0)  133    (1)   54    (2)   43    (3)   53    (4)   62
   (5)   38    (6)   43    (7)   40    (8)   42    (9)   41
Ami ekhono shopno dekhi...
HomePage

albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar » Mon Nov 20, 2006 7:27 pm

thx 4 ur reply..
i got acc.. with my silly mistake..

User avatar
algoJo
New poster
Posts: 37
Joined: Sun Dec 17, 2006 9:02 am

Post by algoJo » Sun Feb 25, 2007 12:45 pm

it's works in my computer but the judges said CE :(
can anybody give me some hints??

Code: Select all

Cut, Thanks to arif_pasha 
}
Last edited by algoJo on Mon Feb 26, 2007 1:15 pm, edited 1 time in total.

arif_pasha
New poster
Posts: 42
Joined: Fri Jun 13, 2003 3:47 pm
Location: Dhaka , Bangladesh
Contact:

Post by arif_pasha » Mon Feb 26, 2007 1:21 am

--> AlgoJo
1. Your program should terminate on input 0

try

Code: Select all

   while(scanf("%d",&n)==1)
   {
	    if(n==0)break;

		memset(res,'0',sizeof(res));
		strcpy(t1,"2");
                ...........
2. It produces incorrect result for input 1

3. It gets "compile error" for the function "itoa". itoa function is not ansi standard.. you should use sprintf..

Code: Select all

itoa(i,t2,10);
sprintf(t2,"%d",i);
both lines does the same..

User avatar
algoJo
New poster
Posts: 37
Joined: Sun Dec 17, 2006 9:02 am

Post by algoJo » Mon Feb 26, 2007 1:13 pm

WooW u're right, Thanks a lot arif_pasha... :D

Md.Arafat Hossain
New poster
Posts: 7
Joined: Fri Mar 02, 2007 10:20 am

WA of 324

Post by Md.Arafat Hossain » Fri Mar 02, 2007 6:04 pm

I do not able to understand why my program produces wrong answer.
Her is my code:
#include<stdio.h>
#include<iostream.h>
int main(){
int i,j,k,b[10],n,c=0,l,m,s;
int a[800] ;

while(cin>>n){
for(i=0;i<800;i++)
a=-1;
for(i=0;i<10;i++)
b=0;

if(n<=366){
i=799;
j=n*(n-1);
while(j>9){
k=j%10;
a=k;
j=j/10;
i--;}
a=j;
for(l=n-2;l>=2;l--){
for(j=799;j>=i;j--){
k=c+l*a[j];
s=j;
m=k%10;
a[s]=m;
k=k/10;
c=k;}
while(c>9){
m=c%10;
s--;
a[s]=m;
c=c/10;}
if(c>0){
s--;
a[s]=c;}

if(i>s) i=s;
c=0;}
k=0;
for(l=0;l<10;l++){
for(j=i;j<800;j++)
if(a[j]==l)
b[l]=++k;
k=0;}
printf("%ld! ---\n",n);
for(l=0;l<10;l++){
if((l==0)&&(l==5))
printf("(%ld)%5ld",l,b[l]);
else
printf(" (%ld)%5ld",l,b[l]);
if(l==4)
printf("\n");}

printf("\n");
}}
return 0;}
[/quote][/url][/list][/list][/code]

Piotr Gawron
New poster
Posts: 1
Joined: Thu Oct 14, 2004 3:44 pm

Post by Piotr Gawron » Fri Mar 02, 2007 6:27 pm

your program gives wrong answer for example input (too many dashes and you shouldn't proceed test where n=0)

jaasilva
New poster
Posts: 1
Joined: Thu Aug 25, 2011 5:24 pm

Re: WA of 324

Post by jaasilva » Thu Aug 25, 2011 5:33 pm

Can anyone help me? (I'm using Java) I can't understand why my program is getting WA. I tested it with all the input that I could find and it was right. I think that's something with the output format. Can someone verify that?

Code: Select all

import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(new BufferedInputStream(System.in));

		int num = in.nextInt();

		while (num != 0)
		{
			BigInteger res = new BigInteger("1");

			for (int i = 2; i <= num; i++)
			{
				BigInteger mul = new BigInteger("" + i);
				res = res.multiply(mul);
			}

			String result = res.toString();
			int[] freq = new int[10];

			for (int j = 0; j < result.length(); j++)
				freq[Integer.parseInt("" + result.charAt(j))]++;

			System.out.printf("%d! --\n", num);
			System.out.printf(
					"   (0) %5d\t(1) %5d\t(2) %5d\t(3) %5d\t(4) %5d\n",
					freq[0], freq[1], freq[2], freq[3], freq[4]);
			System.out.printf(
					"   (5) %5d\t(6) %5d\t(7) %5d\t(8) %5d\t(9) %5d\n",
					freq[5], freq[6], freq[7], freq[8], freq[9]);

			num = in.nextInt();
		}
	}
}

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: WA of 324

Post by uDebug » Tue Apr 08, 2014 7:52 am

jaasilva wrote:Can anyone help me? (I'm using Java) I can't understand why my program is getting WA. I tested it with all the input that I could find and it was right. I think that's something with the output format. Can someone verify that?
This is the output that my AC code uses

Code: Select all

System.out.printf("   (0)%5d    (1)%5d    (2)%5d    (3)%5d    (4)%5d\n", frequencyMap['0'], frequencyMap['1'], frequencyMap['2'], frequencyMap['3'], frequencyMap['4']);   
System.out.printf("   (5)%5d    (6)%5d    (7)%5d    (8)%5d    (9)%5d\n", frequencyMap['5'], frequencyMap['6'], frequencyMap['7'], frequencyMap['8'], frequencyMap['9']);
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 3 (300-399)”