Advertisement
Guest User

Luke T Computing Post-Test Review 29/9/16

a guest
Sep 29th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. static string Question1(string a, string b)
  2. {
  3. string c = "";
  4. int length;
  5. if (a.Length > b.Length) length = a.Length;
  6. else length = b.Length;
  7. for (int i = 0; i < length; i++)
  8. {
  9. if (a.Length > i) c += a[i];
  10. if (b.Length > i) c += b[i];
  11. }
  12. return c;
  13. }
  14.  
  15. static void Question2(int n)
  16. {
  17. for (int i = 1; i <= n; i++)
  18. if (i % 3 == 0 && i % 5 == 0) Console.WriteLine("FizzBuzz");
  19. else if (i % 3 == 0) Console.WriteLine("Fizz");
  20. else if (i % 5 == 0) Console.WriteLine("Buzz");
  21. else Console.WriteLine(i);
  22. }
  23.  
  24. static int Question3(long n)
  25. {
  26. for (int i = 2; i < n / 2; i++)
  27. if (n % i == 0) return i;
  28. return 1;
  29. }
  30.  
  31. static string Question4(string[] strings)
  32. {
  33. bool[] alphabet = new bool[26];
  34. bool correct = true;
  35. string panagram = "";
  36. for (int i = 0; i < strings.Length; i++)
  37. {
  38. for (int r = 0; r < alphabet.Length; r++) alphabet[r] = false;
  39. for (int j = 0; j < strings[i].Length; j++) if (strings[i][j] != ' ') alphabet[(int)strings[i][j] - 97] = true;
  40. for (int k = 0; k < alphabet.Length && correct == true; k++) if (alphabet[k] == false) correct = false;
  41. if (correct) panagram += "1";
  42. else panagram += "0";
  43. correct = true;
  44. }
  45. return panagram;
  46. }
  47.  
  48. //Incomplete
  49. static int Question5()
  50. {
  51. double average;
  52. string initial = Console.ReadLine();
  53. var temp = "";
  54. int? n = null;
  55. int m = 0;
  56. int? a = null;
  57. int? b = null;
  58. int? k = null;
  59. for (int i = 0; i < initial.Length; i++)
  60. {
  61. if (initial[i] != ' ') temp += initial[i];
  62. else
  63. {
  64. if (n == null) n = Convert.ToInt32(temp);
  65. else m = Convert.ToInt32(temp);
  66. }
  67. }
  68. for (int i = 0; i < m; i++)
  69. {
  70. initial = Console.ReadLine();
  71. if (initial[i] != ' ') temp += initial[i];
  72. else
  73. {
  74. if (a == null) a = Convert.ToInt32(temp);
  75. else if (b == null) b = Convert.ToInt32(temp);
  76. else k = Convert.ToInt32(temp);
  77. initial = "";
  78. }
  79. }
  80. }
  81.  
  82. static void Main(string[] args)
  83. {
  84. Console.WriteLine(Question1("abc", "defg"));
  85. Question2(15);
  86. Console.WriteLine(Question3(21));
  87. string[] question4 = new string[] {"we promptly judged antique ivory buckles for the next prize",
  88. "we promptly judged antique ivory buckles for the prizes",
  89. "the quick brown fox jumps over the lazy dog",
  90. "the quick brown fox jump over the lazy dog" };
  91. Console.WriteLine(Question4(question4));
  92. Console.ReadLine();
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement