Advertisement
Vladimir76

Sum and multiplication

Oct 31st, 2020
2,444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Sum
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> arr = new List<int>();
  12.             bool check = false; ;
  13.             int multiplicationValues = 1;
  14.             int inputNumber = int.Parse(Console.ReadLine());
  15.             int endDigit = inputNumber % 10;
  16.  
  17.             if (inputNumber>=100 && inputNumber<=1000)
  18.             {
  19.                 for (int a = 1; a <= 9; a++)
  20.                 {
  21.                     arr.Add(a);
  22.                     for (int b = 9; b >= a; b--)
  23.                     {
  24.                         arr.Add(b);
  25.                         for (int c = 0; c <= 9; c++)
  26.                         {
  27.                             arr.Add(c);
  28.                             for (int d = 9; d >= c; d--)
  29.                             {
  30.                                 arr.Add(d);
  31.                                 int sumArr = arr.Sum();
  32.  
  33.                                 for (int i = 0; i < arr.Count; i++)
  34.                                 {
  35.                                     multiplicationValues *= arr[i];
  36.                                 }
  37.                                 if (sumArr==multiplicationValues && endDigit==5)
  38.                                 {
  39.                                     Console.WriteLine("{0}{1}{2}{3}"
  40.                                         ,arr[0],arr[1],arr[2],arr[3]);
  41.                                     check = true;
  42.                                    
  43.                                     break;
  44.                                 }
  45.                                 int result = multiplicationValues / sumArr;
  46.                                 int resultMod = inputNumber % 3;
  47.                                 if (result==3 && resultMod==0)
  48.                                 {
  49.                                     Console.WriteLine("{0}{1}{2}{3}"
  50.                                         ,arr[3],arr[2],arr[1],arr[0]);
  51.                                     check = true;                                    
  52.                                     break;
  53.                                 }
  54.                                 if (check)
  55.                                 {
  56.                                     break;
  57.                                 }
  58.                                 multiplicationValues = 1;
  59.                                 arr.RemoveAt(3);
  60.                             }
  61.                             if (check)
  62.                             {
  63.                                 break;
  64.                             }
  65.                             multiplicationValues = 1;
  66.                             arr.RemoveAt(2);
  67.                         }
  68.                         if (check)
  69.                         {
  70.                             break;
  71.                         }
  72.                         multiplicationValues = 1;
  73.                         arr.RemoveAt(1);
  74.                     }
  75.                     if (check)
  76.                     {
  77.                         break;
  78.                     }
  79.                     multiplicationValues = 1;
  80.                     arr.RemoveAt(0);
  81.                 }
  82.                 if (check==false)
  83.                 {
  84.                     Console.WriteLine("Nothing found");
  85.                 }
  86.             }          
  87.         }
  88.     }
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement