Advertisement
dydimitrov

Triangle Figure

Nov 25th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TriangleFigure
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. string firstRow = new string('#', 4 * n + 1);
  15. Console.WriteLine(firstRow);
  16.  
  17. int counterDots = 1;
  18. int counterHashTags = (4 * n - 2) / 2;
  19. int counterEmptySpacies = 1;
  20.  
  21. for (int i = 0; i < n; i++)
  22. {
  23. int counterEmptyMiddleRow = (counterEmptySpacies - 3) / 2;
  24. string dots = StringCreater(".", counterDots);
  25. string hashTags = StringCreater("#", counterHashTags);
  26. string emptySpacies = StringCreater(" ", counterEmptySpacies);
  27. string emptySpMiddle = StringCreater(" ", counterEmptyMiddleRow);
  28. if (i == n / 2)
  29. {
  30. Console.WriteLine($"{dots}{hashTags}{emptySpMiddle}(@){emptySpMiddle}" +
  31. $"{hashTags}{dots}");
  32. }
  33. else
  34. {
  35. Console.WriteLine($"{dots}{hashTags}{emptySpacies}" +
  36. $"{hashTags}{dots}");
  37. }
  38.  
  39. counterDots++;
  40. counterHashTags -= 2;
  41. counterEmptySpacies += 2;
  42. }
  43. int counterDotsDown = n + 1;
  44. int counterHash = (4 * n - 1) / 2;
  45.  
  46. for (int i = 0; i < n; i++)
  47. {
  48. string dots = StringCreater(".", counterDotsDown);
  49. string hash = StringCreater("#", counterHash);
  50. Console.WriteLine($"{dots}{hash}{dots}");
  51. counterDotsDown++;
  52. counterHash -= 2;
  53. }
  54. }
  55.  
  56. public static string StringCreater(string text, int repeatCount)
  57. {
  58. string repeatedText = string.Empty;
  59. for (int currentCount = 0; currentCount < repeatCount; currentCount++)
  60. {
  61. repeatedText += text;
  62. }
  63. return repeatedText;
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement