Advertisement
Guest User

Problem 3 – Ones and Zeros

a guest
Apr 5th, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. string zeroTopBottom = "###";
  8. string zeroBody = "#.#";
  9. string oneTopBody = ".#.";
  10. string oneUnique = "##.";
  11.  
  12. int input = int.Parse(Console.ReadLine());
  13.  
  14. string binary = Convert.ToString(input, 2).PadLeft(32, '0');
  15.  
  16. for (int row = 0; row < 5; row++)
  17. {
  18. for (int bit = 16; bit < binary.Length; bit++)
  19. {
  20. if (binary[bit] == '0')
  21. {
  22. if (row == 0 || row == 4)
  23. {
  24. Console.Write(zeroTopBottom);
  25. }
  26. else
  27. {
  28. Console.Write(zeroBody);
  29. }
  30. }
  31. else
  32. {
  33. if (row == 1)
  34. {
  35. Console.Write(oneUnique);
  36. }
  37. else if (row == 4)
  38. {
  39. Console.Write(zeroTopBottom);
  40. }
  41. else
  42. {
  43. Console.Write(oneTopBody);
  44. }
  45. }
  46. if (bit != binary.Length - 1)
  47. {
  48. Console.Write('.');
  49. }
  50. }
  51. Console.WriteLine();
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement