Advertisement
Stan0033

Untitled

Jun 18th, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace apps
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. static string Get() { return Console.ReadLine(); }
  10. // 08. Condense Array to Number
  11.  
  12. //-----------------------------------------------------------------------------------------
  13. //-----------------------------------------------------------------------------------------
  14. //-----------------------------------------------------------------------------------------
  15. //-----------------------------------------------------------------------------------------
  16. string Condensing = Get();
  17. if (Condensing.Length == 1) { Console.WriteLine("1 is already condensed to number"); }
  18. else
  19. {
  20. while (true)
  21. {
  22.  
  23.  
  24. string[] inputArray = Condensing.Split(' '); // convert the string into array
  25. int[] nums = new int[inputArray.Length ]; // create int array
  26. for (int i = 0; i < nums.Length; i++) { try { nums[i] = Convert.ToInt32(inputArray[i]); } catch { Console.WriteLine(inputArray[i]); } }// transfer the array into int array
  27. Condensing = string.Empty; // reset the string to be re-written for the next cycle
  28.  
  29. //-----------------------------------------------------------------------------------------
  30.  
  31. for (int i = 0; i < nums.Length - 1; i++) { if (nums[i + 1] != 0) { Condensing += (nums[i] + nums[i + 1]).ToString() + " "; Console.WriteLine($"{nums[i]} + {nums[i+1]} = {nums[i] + nums[i+1]}"); } } // create new array of the added nums.
  32.  
  33.  
  34. if (Condensing.Length <= 3) { break; }
  35. }
  36. Console.WriteLine(Condensing);
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. }
  48.  
  49.  
  50. }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement