Advertisement
braveheart1989

Largest Product of Digits

May 15th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 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 _06.Largest_Product_Of_Digits
  8. {
  9.     class Largest_Product_Of_Digits
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             int product = 1;
  15.             int maxProduct = int.MinValue;
  16.             int currentPosition = 0;
  17.             for (int i = 0; i < input.Length; i++)
  18.             {
  19.                 for (int j = 0; j < 6; j++)
  20.                 {                  
  21.                     product *= Convert.ToInt32(input[currentPosition] - 48);
  22.  
  23.                     if (currentPosition < input.Length - 1)
  24.                     {
  25.                         currentPosition++;
  26.                     }
  27.                 }
  28.                 if (product > maxProduct)
  29.                 {
  30.                     maxProduct = product;
  31.                     product = 1;
  32.                 }
  33.                 else
  34.                 {
  35.                     product = 1;
  36.                 }
  37.                 currentPosition = i + 1;
  38.             }
  39.             Console.WriteLine(maxProduct);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement