123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <math.h>
- using namespace std;
- struct time
- {
- int hours, minutes, seconds;
- };
- struct day_info
- {
- struct time rise, culmination, setting;
- int day_size;
- };
- struct day_info get_day_info(ifstream* file)
- {
- int YMD, HMS, nextYMD, nextHMS, headBytes;
- double El, nextT, nextR, nextEl, nextAz, nextFI, nextLG, prevEl;
- struct time rise, culmination, setting;
- *file >> nextYMD >> nextHMS >> nextT >> nextR >> nextEl >> nextAz >> nextFI >> nextLG;
- headBytes = file->tellg();
- YMD = nextYMD;
- HMS = nextHMS;
- El = nextEl;
- *file >> nextYMD >> nextHMS >> nextT >> nextR >> nextEl >> nextAz >> nextFI >> nextLG;
- while(YMD == nextYMD)
- {
- // cout << El << ' ' << nextEl << endl;
- if (El < 0 and nextEl > 0)
- {
- // cout << "rise /|" << endl;
- rise.hours = nextHMS/10000;
- rise.minutes = (nextHMS/100)%100;
- rise.seconds = nextHMS%100;
- }
- else if (El > prevEl and El > nextEl and El > 0 and nextEl > 0 and prevEl > 0)
- {
- // cout << "culmination /|" << endl;
- culmination.hours = HMS/10000;
- culmination.minutes = (HMS/100)%100;
- culmination.seconds = HMS%100;
- }
- else if (El > 0 and nextEl < 0)
- {
- // cout << "setting /|" << endl;
- setting.hours = nextHMS/10000;
- setting.minutes = (nextHMS/100)%100;
- setting.seconds = nextHMS%100;
- }
- YMD = nextYMD;
- HMS = nextHMS;
- prevEl = El;
- El = nextEl;
- *file >> nextYMD >> nextHMS >> nextT >> nextR >> nextEl >> nextAz >> nextFI >> nextLG;
- cout << nextYMD << ' ' << nextHMS << ' ' << nextT << ' ' << nextR << ' ' << nextEl << ' ' << nextAz << ' ' << nextFI << ' ' << nextLG << endl;
- }
- struct day_info day_result;
- day_result.rise = rise;
- day_result.culmination = culmination;
- day_result.setting = setting;
- day_result.day_size = file->tellg() - headBytes;
- return day_result;
- }
- int countDays(int year, int months, int day)
- {
- months -= 1;
- int result = (months/2)*30 + (months/2 + months%2)*31;
- if (months > 1) result -= 2;
- if (months > 1 and year % 4 == 0) result += 1;
- if (months > 5) result += 1;
- return result + day;
- }
- int main() {
- ifstream file;
- string filepath = "Moon/moon";
- int year, month, day;
- cin >> year >> month >> day;
- for(int i = 0; i < 4; i++) {
- cout << (year / (int)pow(10, 3-i))%10 << endl;
- filepath += char((year / (int)pow(10, 3-i))%10 + '0');
- }
- filepath += ".dat";
- cout << filepath << endl;
- file.open(filepath);
- if(file) {
- string s;
- getline(file, s);
- cout << s << endl;
- int headsize = file.tellg();
- struct day_info first_day = get_day_info(&file);
- cout << first_day.day_size << endl;
- cout << countDays(year, month, day) << endl;
- file.seekg( countDays(year, month, day) * (first_day.day_size) + headsize, ios_base::beg);
- struct day_info day_result = get_day_info(&file);
- cout << day_result.rise.hours << ':' << day_result.rise.minutes << ':' << day_result.rise.seconds << endl;
- cout << day_result.culmination.hours << ':' << day_result.culmination.minutes << ':' << day_result.culmination.seconds << endl;
- cout << day_result.setting.hours << ':' << day_result.setting.minutes << ':' << day_result.setting.seconds << endl;
- // int days = 100;
- // int prevSize = 0;
- // for(int i = 0; i < days; i++) {
- // struct day_info first_day = get_day_info(&file);
- // cout << first_day.day_size - prevSize << endl;
- // prevSize = first_day.day_size;
- // }
- }
- return 0;
- }
|