Advertisement
Stan0033

Untitled

Jun 25th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace strong_number
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. //Sum Adjacent Equal Numbers
  11. // 3 3 4 = 6 4
  12. // 3 3 6 4 = 6 6 4 = 12 4
  13. List<double> list = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
  14.  
  15. int occured = 0;
  16.  
  17. while (true)
  18. {
  19.  
  20. for (int i=0; i< list.Count; i++)
  21. if (i + 1 < list.Count)
  22. {
  23. if (list[i] == list[i + 1])
  24. {
  25. list[i] += list[i + 1];
  26.  
  27. list.RemoveAt(i + 1);
  28. break;
  29.  
  30. }
  31. else
  32. {
  33. occured++;
  34. if (occured== list.Count - 1) { goto print; }
  35. }
  36. }
  37. occured = 0;
  38. }
  39.  
  40.  
  41. print:
  42. Console.WriteLine(string.Join(" ", list));
  43. }
  44. }
  45. }
  46.  
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement