asdfg0998

Untitled

Jun 16th, 2025
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. string getLunarPhase(string season, int dayCount, string initialPhase) {
  2.     vector<string> phases = {
  3.         "NewMoon", "Crescent", "Quarter", "Gibbous",
  4.         "Full", "Waning", "Eclipse", "Twilight"
  5.     };
  6.  
  7.     unordered_map<string, int> monthDays = {
  8.         {"January", 31}, {"February", 28}, {"March", 31}, {"April", 30},
  9.         {"May", 31}, {"June", 30}, {"July", 31}, {"August", 31},
  10.         {"September", 30}, {"October", 31}, {"November", 30}, {"December", 31}
  11.     };
  12.  
  13.     unordered_map<string, int> phaseIndex;
  14.     for (int i = 0; i < phases.size(); ++i)
  15.         phaseIndex[phases[i]] = i;
  16.  
  17.     // Step 1: Calculate total days from Jan 1 to (season, dayCount)
  18.     int daysPassed = 0;
  19.     for (auto& [month, days] : monthDays) {
  20.         if (month == season) break;
  21.         daysPassed += days;
  22.     }
  23.     daysPassed += (dayCount - 1);  // 0-based offset
  24.  
  25.     // Step 2: Compute the resulting phase
  26.     int startPhaseIdx = phaseIndex[initialPhase];
  27.     int resultIdx = (startPhaseIdx + daysPassed) % 8;
  28.     return phases[resultIdx];
  29. }
Advertisement
Add Comment
Please, Sign In to add comment