main.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <math.h>
  6. using namespace std;
  7. struct time
  8. {
  9. int hours, minutes, seconds;
  10. };
  11. struct day_info
  12. {
  13. struct time rise, culmination, setting;
  14. int day_size;
  15. };
  16. struct day_info get_day_info(ifstream* file)
  17. {
  18. int YMD, HMS, nextYMD, nextHMS, headBytes;
  19. double El, nextT, nextR, nextEl, nextAz, nextFI, nextLG, prevEl;
  20. struct time rise, culmination, setting;
  21. *file >> nextYMD >> nextHMS >> nextT >> nextR >> nextEl >> nextAz >> nextFI >> nextLG;
  22. headBytes = file->tellg();
  23. YMD = nextYMD;
  24. HMS = nextHMS;
  25. El = nextEl;
  26. *file >> nextYMD >> nextHMS >> nextT >> nextR >> nextEl >> nextAz >> nextFI >> nextLG;
  27. while(YMD == nextYMD)
  28. {
  29. // cout << El << ' ' << nextEl << endl;
  30. if (El < 0 and nextEl > 0)
  31. {
  32. // cout << "rise /|" << endl;
  33. rise.hours = nextHMS/10000;
  34. rise.minutes = (nextHMS/100)%100;
  35. rise.seconds = nextHMS%100;
  36. }
  37. else if (El > prevEl and El > nextEl and El > 0 and nextEl > 0 and prevEl > 0)
  38. {
  39. // cout << "culmination /|" << endl;
  40. culmination.hours = HMS/10000;
  41. culmination.minutes = (HMS/100)%100;
  42. culmination.seconds = HMS%100;
  43. }
  44. else if (El > 0 and nextEl < 0)
  45. {
  46. // cout << "setting /|" << endl;
  47. setting.hours = nextHMS/10000;
  48. setting.minutes = (nextHMS/100)%100;
  49. setting.seconds = nextHMS%100;
  50. }
  51. YMD = nextYMD;
  52. HMS = nextHMS;
  53. prevEl = El;
  54. El = nextEl;
  55. *file >> nextYMD >> nextHMS >> nextT >> nextR >> nextEl >> nextAz >> nextFI >> nextLG;
  56. cout << nextYMD << ' ' << nextHMS << ' ' << nextT << ' ' << nextR << ' ' << nextEl << ' ' << nextAz << ' ' << nextFI << ' ' << nextLG << endl;
  57. }
  58. struct day_info day_result;
  59. day_result.rise = rise;
  60. day_result.culmination = culmination;
  61. day_result.setting = setting;
  62. day_result.day_size = file->tellg() - headBytes;
  63. return day_result;
  64. }
  65. int countDays(int year, int months, int day)
  66. {
  67. months -= 1;
  68. int result = (months/2)*30 + (months/2 + months%2)*31;
  69. if (months > 1) result -= 2;
  70. if (months > 1 and year % 4 == 0) result += 1;
  71. if (months > 5) result += 1;
  72. return result + day;
  73. }
  74. int main() {
  75. ifstream file;
  76. string filepath = "Moon/moon";
  77. int year, month, day;
  78. cin >> year >> month >> day;
  79. for(int i = 0; i < 4; i++) {
  80. cout << (year / (int)pow(10, 3-i))%10 << endl;
  81. filepath += char((year / (int)pow(10, 3-i))%10 + '0');
  82. }
  83. filepath += ".dat";
  84. cout << filepath << endl;
  85. file.open(filepath);
  86. if(file) {
  87. string s;
  88. getline(file, s);
  89. cout << s << endl;
  90. int headsize = file.tellg();
  91. struct day_info first_day = get_day_info(&file);
  92. cout << first_day.day_size << endl;
  93. cout << countDays(year, month, day) << endl;
  94. file.seekg( countDays(year, month, day) * (first_day.day_size) + headsize, ios_base::beg);
  95. struct day_info day_result = get_day_info(&file);
  96. cout << day_result.rise.hours << ':' << day_result.rise.minutes << ':' << day_result.rise.seconds << endl;
  97. cout << day_result.culmination.hours << ':' << day_result.culmination.minutes << ':' << day_result.culmination.seconds << endl;
  98. cout << day_result.setting.hours << ':' << day_result.setting.minutes << ':' << day_result.setting.seconds << endl;
  99. // int days = 100;
  100. // int prevSize = 0;
  101. // for(int i = 0; i < days; i++) {
  102. // struct day_info first_day = get_day_info(&file);
  103. // cout << first_day.day_size - prevSize << endl;
  104. // prevSize = first_day.day_size;
  105. // }
  106. }
  107. return 0;
  108. }