Problem Statement
This problem is a programming version of Problem 8 from projecteuler.net
Find the greatest product ofK consecutive digits in the N digit number.
Input Format
First line containsT that denotes the number of test cases.
First line of each test case will contain two integersN & K .
Second line of each test case will contain aN digit integer.
Output Format
Print the required answer for each test case.
Constraints
1≤T≤100
1≤K≤7
K≤N≤1000
Sample Input
Find the greatest product of
Input Format
First line contains
First line of each test case will contain two integers
Second line of each test case will contain a
Output Format
Print the required answer for each test case.
Constraints
Sample Input
2
10 5
3675356291
10 5
2709360626
Sample Output 3150
0
MY SOLUTION:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t!=0)
{
int k=s.nextInt();
int n=s.nextInt();
String a=s.next();
int i,j,count=0,max=0,sum=1;
j=n;
while(j!=k)
{
String b=a.substring(count,j);
count++;
j++;
sum=1;
for(i=0;i<b.length();i++)
{
sum=sum*Character.getNumericValue(b.charAt(i));
}
if(max<sum)
max=sum;
}
System.out.println(max);
}
t--;
}
}
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t!=0)
{
int k=s.nextInt();
int n=s.nextInt();
String a=s.next();
int i,j,count=0,max=0,sum=1;
j=n;
while(j!=k)
{
String b=a.substring(count,j);
count++;
j++;
sum=1;
for(i=0;i<b.length();i++)
{
sum=sum*Character.getNumericValue(b.charAt(i));
}
if(max<sum)
max=sum;
}
System.out.println(max);
}
t--;
}
}