![:)](./images/smilies/icon_smile.gif)
993 - Product of digits
Moderator: Board moderators
Re: 993 - Product of digits
Thanks CSGrandeur... you made me realize I was factorizing the digits in the wrong direction
, instead of 2 -> 9
![:)](./images/smilies/icon_smile.gif)
all that matters is AC
-
- New poster
- Posts: 39
- Joined: Tue Aug 07, 2012 10:40 pm
- Location: BUBT,Dhaka, Bangladesh
- Contact:
Re: 993 - Product of digits
Nice Problem....
Sample Input and Output:
Input:
Output:
![:)](./images/smilies/icon_smile.gif)
Sample Input and Output:
Input:
Code: Select all
20
0
1
2
7
9
10
48
96
18
100000000
7523475
643
156236
19
23
6746
59049
387420489
430467221
373248
Code: Select all
0
1
2
7
9
25
68
268
29
45555555588
-1
-1
-1
-1
-1
-1
99999
999999999
-1
888999
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/
Re: 993 - Product of digits
got AC-ed ![:D](./images/smilies/icon_biggrin.gif)
![:D](./images/smilies/icon_biggrin.gif)
Re: 993 - Product of digits
Hiya, I keep getting Runtime Errors and I can't fathom why. Help, please?
![:)](./images/smilies/icon_smile.gif)
Code: Select all
import java.util.*;
import java.io.*;
public class P993
{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void main(String[] args) throws IOException
{
int numCases = Integer.parseInt(br.readLine());
for(int i=0; i<numCases; i++)
{
// int n = Integer.parseInt(br.readLine());
long n = Long.parseLong(br.readLine());
String ans = process(n);
// pw.println(process(n));
if(ans.equals("-1") || ans.length()==1)
pw.println(ans);
else
{
int prod = Integer.parseInt(ans.charAt(0)+"");
StringBuilder sb = new StringBuilder();
int last = 0;
for(int j=1; j<ans.length(); j++)
{
int d = Integer.parseInt(ans.charAt(j)+"");
if(prod * d >9)
{
sb.append(prod);
prod = d;
last = j;
}
else
prod*=d;
}
sb.append(ans.substring(last));
char[] c = sb.toString().toCharArray();
Arrays.sort(c);
pw.println(new String(c));
}
}
pw.close();
}
static String process(long n)
{
if(n>9)
{
for(int i=9; i>=2; i--)
{
if(n%i==0)
{
String s = process(n/i);
if(s.equals("-1"))
continue;
else
return i+""+process(n/i);
}
}
}
else
return n+"";
return "-1";
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 993 - Product of digits
use class Main
Check input and AC output for thousands of problems on uDebug!