Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace apps
- {
- class Program
- {
- static void Main(string[] args)
- {
- static string Get() { return Console.ReadLine(); }
- // 08. Condense Array to Number
- //-----------------------------------------------------------------------------------------
- //-----------------------------------------------------------------------------------------
- //-----------------------------------------------------------------------------------------
- //-----------------------------------------------------------------------------------------
- string Condensing = Get();
- if (Condensing.Length == 1) { Console.WriteLine("1 is already condensed to number"); }
- else
- {
- while (true)
- {
- string[] inputArray = Condensing.Split(' '); // convert the string into array
- int[] nums = new int[inputArray.Length ]; // create int array
- 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
- Condensing = string.Empty; // reset the string to be re-written for the next cycle
- //-----------------------------------------------------------------------------------------
- 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.
- if (Condensing.Length <= 3) { break; }
- }
- Console.WriteLine(Condensing);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement