-
Notifications
You must be signed in to change notification settings - Fork 0
/
E8.java
41 lines (40 loc) · 921 Bytes
/
E8.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//Find the greatest product of K consecutive digits in the digit number N.
import java.util.Scanner;
class E8
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int ar[]=new int[t];
for(int x=0;x<t;x++)
{
int a=sc.nextInt();
int b=sc.nextInt();
String s=sc.next();
int y=0;
while(y<=a-b)
{
int ab=pro(s.substring(y,y+b));
if(ab>ar[x])
{
ar[x]=ab;
}
y++;
}
}
for(int x=0;x<t;x++)
{
System.out.println(ar[x]);
}
}
public static int pro(String s)
{
int pro=1;
for(int x=0;x<s.length();x++)
{
pro*=s.charAt(x)-48;
}
return pro;
}
}