Input:
Code: Select all
273
0
Code: Select all
273! --
(0) 133 (1) 54 (2) 43 (3) 53 (4) 62
(5) 38 (6) 43 (7) 40 (8) 42 (9) 41
Moderator: Board moderators
Code: Select all
273
0
Code: Select all
273! --
(0) 133 (1) 54 (2) 43 (3) 53 (4) 62
(5) 38 (6) 43 (7) 40 (8) 42 (9) 41
Code: Select all
Cut, Thanks to arif_pasha
}
Code: Select all
while(scanf("%d",&n)==1)
{
if(n==0)break;
memset(res,'0',sizeof(res));
strcpy(t1,"2");
...........
Code: Select all
itoa(i,t2,10);
sprintf(t2,"%d",i);
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();
}
}
}
This is the output that my AC code usesjaasilva 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?
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']);