Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. if (args[0] == "gen")
  8. GenerateRandom();
  9. else if (args[0] == "len")
  10. Console.WriteLine(Measure().ToString("0.00"));
  11. }
  12.  
  13. static void GenerateRandom()
  14. {
  15. Random rnd = new Random();
  16.  
  17. int len = rnd.Next(2, 101); // [2, 100]
  18.  
  19. string blank = new string(' ', 10);
  20. char[] ls = blank.ToCharArray();
  21. int ln = -1;
  22.  
  23. for (int i = 0; i < len; i++)
  24. {
  25. char[] s = blank.ToCharArray();
  26.  
  27. int n = rnd.Next(0, 10); // [0, 9]
  28.  
  29. s[n] = '#';
  30.  
  31. for (int j = n; ln != -1 && j != ln && ls[j] == ' '; j += Math.Sign(ln - n))
  32. {
  33. s[j] = '#';
  34. }
  35.  
  36. ln = n;
  37. ls = s;
  38.  
  39. Console.WriteLine(s);
  40. }
  41. }
  42.  
  43. static double Measure()
  44. {
  45. string[] lines = Console.In.ReadToEnd().Split('\n');
  46.  
  47. string ls = lines[0];
  48. int ln = lines[0].IndexOf('#');
  49. double acc = 0;
  50.  
  51. for (int i = 1; i < lines.Length; i++)
  52. {
  53. string s = lines[i];
  54.  
  55. if (string.IsNullOrEmpty(s))
  56. break;
  57.  
  58. int n = -1;
  59.  
  60. for (int j = 0; j < 10; j++)
  61. {
  62. if (s[j] == '#')
  63. {
  64. if (n < 0 || j > ln)
  65. n = j;
  66. }
  67. }
  68.  
  69. int d = ln - n;
  70. acc += Math.Round(Math.Sqrt(d * d + 1), 2);
  71.  
  72. ls = s;
  73. ln = n;
  74. }
  75.  
  76. return Math.Round(acc, 2);
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement