fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace CodeChefConsoleApplication
  5. {
  6. class SumsInATriangle
  7. {
  8. static void Main(string[] args)
  9. {
  10. short n = short.Parse(Console.ReadLine());
  11. StringBuilder sb = new StringBuilder();
  12. while (n-- > 0)
  13. {
  14. int lines = Int32.Parse(Console.ReadLine());
  15. int[] row = new int[lines];
  16. for (int i = 0; i < lines; i++)
  17. {
  18. int[] tempRow = new int[lines];
  19. string str = Console.ReadLine();
  20. int j = 0;
  21. foreach (String sub in str.Split(' '))
  22. {
  23. int element = Int32.Parse(sub);
  24. tempRow[j] = Math.Max(element + getElement(row, j), element + getElement(row, j - 1));
  25. j++;
  26. }
  27. row = tempRow;
  28. }
  29. int max = Int32.MinValue;
  30. foreach (int t in row)
  31. if (t > max)
  32. max = t;
  33. sb.Append(max);
  34. if (n > 0)
  35. sb.Append("\n");
  36. }
  37. Console.WriteLine(sb);
  38. }
  39. private static int getElement(int[] list, int p)
  40. {
  41. if (p < 0 || p >= list.Length || list.Length == 0)
  42. return 0;
  43. else
  44. return list[p];
  45. }
  46. }
  47. }
Runtime error #stdin #stdout #stderr 0.04s 36488KB
stdin
2
3
1
2 1
1 2 3
4 
1 
1 2 
4 1 2
2 3 1 1 
stdout
Standard output is empty
stderr
Unhandled Exception: System.FormatException: Input string was not in the correct format
  at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0 
  at CodeChefConsoleApplication.SumsInATriangle.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: Input string was not in the correct format
  at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0 
  at CodeChefConsoleApplication.SumsInATriangle.Main (System.String[] args) [0x00000] in <filename unknown>:0