Program.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* 1
  2. Console.Write("Введите год: ");
  3. int year21 = int.Parse(Console.ReadLine());
  4. for (int year = 1900; year <= 1999; year++)
  5. {
  6. for (int month = 1; month <= 12; month++)
  7. {
  8. for (int day = 1; day < DateTime.DaysInMonth(year,month); day++)
  9. {
  10. bool a = dob(year21, year, month, day);
  11. if (a == true)
  12. {
  13. Console.WriteLine( new DateTime(year,month,day).ToShortDateString());
  14. }
  15. }
  16. }
  17. }
  18. static bool dob(int year21, int year, int moth, int day)
  19. {
  20. int sq = 0;
  21. foreach (var numb in year.ToString())
  22. {
  23. sq += Convert.ToInt32(numb.ToString()) * Convert.ToInt32(numb.ToString());
  24. }
  25. if (sq - day * day == year21 - year)
  26. {
  27. return true;
  28. }
  29. else
  30. {
  31. return false;
  32. }
  33. }
  34. */
  35. /* 2
  36. Console.Write("string: ");
  37. string str = Console.ReadLine();
  38. string newstr = "";
  39. int count = 1;
  40. for (int i = 0; i < str.Length; i++)
  41. {
  42. if (i == str.Length - 1 || str[i] != str[i + 1])
  43. {
  44. if (count == 1)
  45. {
  46. newstr += str[i];
  47. count = 1;
  48. }
  49. else
  50. {
  51. newstr += count.ToString() + str[i];
  52. count = 1;
  53. }
  54. }
  55. else
  56. {
  57. count++;
  58. }
  59. }
  60. Console.WriteLine(newstr);
  61. */
  62. /* 3
  63. Console.Write("Загадайте число: ");
  64. string numbertrue = Console.ReadLine();
  65. Console.Write("Предположите число: ");
  66. string numbertry = Console.ReadLine();
  67. Console.WriteLine($"Быков: {bulls(numbertrue,numbertry)}, коров: {cows(numbertrue,numbertry)}");
  68. static int bulls(string str1, string str2)
  69. {
  70. int bulls = 0;
  71. for (int i = 0; i < str1.Length; i++)
  72. {
  73. if (str1[i] == str2[i])
  74. {
  75. bulls++;
  76. }
  77. }
  78. return bulls;
  79. }
  80. static int cows(string str1, string str2)
  81. {
  82. int cows = 0;
  83. for (int i = 0; i < str1.Length; i++)
  84. {
  85. for (int j = 0; j < str2.Length; j++)
  86. {
  87. if (str1 [i] == str2[j])
  88. {
  89. if (i != j)
  90. {
  91. cows++;
  92. }
  93. }
  94. }
  95. }
  96. return cows;
  97. }
  98. */