You are viewing a single comment's thread. Return to all comments →
using System; using System.Collections.Generic; using System.IO; using System.Linq;
using System;
class Solution { static void Main(String[] args) { int t = Convert.ToInt32(Console.ReadLine());
for(int a0 = 0; a0 < t; a0++) { string[] tokens_n = Console.ReadLine().Split(' '); int n = Convert.ToInt32(tokens_n[0]); int k = Convert.ToInt32(tokens_n[1]); string num = Console.ReadLine(); long maxProduct = GetMaxProduct(n, k, num); Console.WriteLine(maxProduct); } } static long GetMaxProduct(int n, int k, string num) { long maxProduct = 0; for (int i = 0; i <= n - k; i++) { long product = 1; for (int j = 0; j < k; j++) { int digit = int.Parse(num.Substring(i + j, 1)); product *= digit; } maxProduct = Math.Max(maxProduct, product); } return maxProduct; }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #8: Largest product in a series
You are viewing a single comment's thread. Return to all comments →
using System; using System.Collections.Generic; using System.IO; using System.Linq;
using System;
class Solution { static void Main(String[] args) { int t = Convert.ToInt32(Console.ReadLine());
}