fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4. #include <fstream>
  5. #include <string>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. std::vector<int> getdataday( int month ) {
  11.  
  12. std::vector<int> vec;
  13.  
  14. switch(month)
  15. {
  16. case 1:
  17. break;
  18. case 2:
  19. vec.push_back(11);
  20. vec.push_back(15);
  21. vec.push_back(17);
  22. break;
  23. default:
  24. break;
  25. }
  26.  
  27.  
  28. return vec;
  29. }
  30.  
  31. std::string getdatamonth( int day, int month, int year ) {
  32.  
  33. std::string str = "";
  34.  
  35. switch(month)
  36. {
  37. case 1:
  38. str += "";
  39. break;
  40. case 2:
  41. str += "11 родилась Инна Фролова " + std::to_string(year - 1970) + " лет назад";
  42. if (day == 11) str += "!!!";
  43. str += "\n";
  44.  
  45. str += "15 родилась Тамара Артюшкина " + std::to_string(year - 1952) + " лет назад";
  46. if (day == 15) str += "!!!";
  47. str += "\n";
  48.  
  49. str += "17 родился Сергей Солодовников " + std::to_string(year - 1998) + " лет назад";
  50. if (day == 17) str += "!!!";
  51. str += "\n";
  52.  
  53. break;
  54. default:
  55. str += "";
  56. break;
  57. }
  58.  
  59.  
  60. return str;
  61. }
  62.  
  63. int main() {
  64.  
  65. setlocale(LC_ALL, "Russian");
  66. /*
  67. std::string line;
  68.  
  69.   std::ifstream in("data.txt"); // окрываем файл для чтения
  70. if (in.is_open())
  71.   {
  72.   while (std::getline(in, line))
  73.   {
  74.   std::cout << line << std::endl;
  75.   }
  76.   }
  77.   in.close(); // закрываем файл
  78. */
  79. const int MAXLEN = 80;
  80. char s[MAXLEN];
  81. time_t tm = time(0);
  82.  
  83. strftime(s, MAXLEN, "%m", localtime(&tm));
  84. int month = atoi( s );
  85.  
  86. strftime(s, MAXLEN, "%d", localtime(&tm));
  87. int day = atoi( s );
  88.  
  89. strftime(s, MAXLEN, "%Y", localtime(&tm));
  90. int year = atoi( s );
  91.  
  92. cout << " —------------------------------" << endl;
  93. cout << " Календарь - " << year << endl;
  94. cout << " —------------------------------" << endl << endl;
  95.  
  96. string monthsList[12] = {"Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"};
  97. int mDays [12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  98.  
  99. /*
  100. 1) Определим номер дня недели, где:
  101.  
  102. 0 - Понедельник
  103. 1 - Вторник
  104. 2 - Среда
  105. 3 - Четверг
  106. 4 - Пятница
  107. 5 - Суббота
  108. 6 - Воскресенье
  109.  
  110. */
  111. int days;
  112. int current;
  113.  
  114. static int t[] = {6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
  115. int y = year%100;
  116.  
  117. current = y/12 + y%12 + y%12/4 + t[month-1] + (20-year/100);
  118. if ((year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) && month <= 2) current--;
  119. current = current%7;
  120. /*
  121. 2) Проверка на високосность начиная с нулевого месяца:
  122. 0 - январь
  123. ...
  124. 11 - декабрь
  125. */
  126.  
  127. if( month == 2 ) // 1 - это февраль месяц, так как счёт начинается с 0.
  128. if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
  129. days = 29; // Если високосный
  130. else
  131. days = mDays[month - 1];
  132. else
  133. days = mDays[month - 1];
  134.  
  135. /*
  136. 3) Выводим сам календарь
  137. */
  138.  
  139. cout << endl << " —----------" << monthsList[month - 1] << "-------------" << endl;
  140.  
  141. cout << " Пн" << " Вт" << " Ср" << " Чт" << " Пт" << " Сб" << " Вс" << endl;
  142.  
  143. /*
  144. 4) Вводим доп. переменные k и j:
  145. k - количество дней в неделе от 0 до 6 (0 - ПН; 6 - ВС)
  146. j - количество дней в месяце (от 1 до общего в месяце)
  147. */
  148.  
  149. int k;
  150. std::vector<int> vec = getdataday(month);
  151.  
  152. for (k = 0; k < current; k++) cout << " ";
  153.  
  154.  
  155. for (int j = 1; j <= days; j++) {
  156.  
  157. k++;
  158. bool flag = true;
  159. if (j == day) {
  160. if (j < 10) cout << " " << "{" << j << "}"; else cout << " " << "{" << j << "}";
  161. flag = false;
  162. }
  163.  
  164. for (int i = 0; i <= vec.size(); i++) if ((j == vec[i])&&(flag)) {
  165. if (j < 10) cout << " " << "[" << j << "]"; else cout << " " << "[" << j << "]";
  166. flag = false;
  167. }
  168.  
  169. if (flag) {
  170. if (j < 10) cout << " " << j; else cout << " " << j;
  171. }
  172.  
  173. if (k > 6)
  174. {
  175. k = 0;
  176. cout << endl;
  177. }
  178.  
  179. if (k)
  180. {
  181. // cout << endl;
  182. current = k;
  183. }
  184. }
  185. cout << getdatamonth(day,month,year);
  186.  
  187. return 0;
  188. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
 —------------------------------
 Календарь - 2024
 —------------------------------


 —----------Февраль-------------
   Пн   Вт   Ср   Чт   Пт   Сб   Вс
                   1    2  {3}    4
    5    6    7    8    9   10 [11]
   12   13   14 [15]   16 [17]   18
   19   20   21   22   23   24   25
   26   27   28   2911 родилась Инна   Фролова 54 лет назад
15 родилась Тамара Артюшкина 72 лет назад
17 родился  Сергей Солодовников 26 лет назад