Advertisement
iskren_penev

ProductOf6Digits

May 15th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LargestProductOfDigits
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             Console.WriteLine(FindMaxProduct(input));
  15.         }
  16.         static int FindMaxProduct(string s)
  17.         {
  18.             int maxProduct = 0;
  19.             for (int i = 0; i < s.Length - 6; i++)
  20.             {
  21.                 int temp = 1;
  22.                 temp *= int.Parse(s[i].ToString());
  23.                 temp *= int.Parse(s[i + 1].ToString());
  24.                 temp *= int.Parse(s[i + 2].ToString());
  25.                 temp *= int.Parse(s[i + 3].ToString());
  26.                 temp *= int.Parse(s[i + 4].ToString());
  27.                 temp *= int.Parse(s[i + 5].ToString());
  28.                 if (temp > maxProduct)
  29.                 {
  30.                     maxProduct = temp;
  31.                 }
  32.             }
  33.             return maxProduct;
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement