让网站快速收录,福州网站开发培训,外包做网站哪家好,中美关系最新消息2021本地AC#xff0c;CCF编译失败。 通过对每条任务进行处理#xff0c;将可能的月#xff0c;日处理出来#xff0c;并且比对对应星期是否符合要求。再对时分进行处理#xff0c;判断整体时间在所给区域内。 思路借鉴自https://blog.csdn.net/gl486546/article/details/7905…本地ACCCF编译失败。 通过对每条任务进行处理将可能的月日处理出来并且比对对应星期是否符合要求。再对时分进行处理判断整体时间在所给区域内。 思路借鉴自https://blog.csdn.net/gl486546/article/details/79057666 #includeiostream
#includestring
#includemap
#includevectorusing namespace std;
char vMon[][4] { ,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec };
char vWek[][4] { sun,mon,tue,wed,thu,fri,sat };
int monthArray[] { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
mapstring, int mMon, mWeek;//map string to int
mapstring, vectorstring mrt;//time - commands //results
void bulidMonAndWeekMap() {for (int i 1; i 12; i) mMon[vMon[i]] i;for (int i 0; i 6; i) mWeek[vWek[i]] i;//
}
void standlize(string s) {for (int i 0; is.size(); i) {s[i] tolower(s[i]);}
}bool isLeapYear(int y) {return (y % 400 0) || (y % 4 0 y % 100);
}
int getDayOfWeek(int year, int month, int dayOfMonth) {//calculate days from 1970-01-01,of which the dayOfWeek is 4.int count 0;for (int i 1970; i year; i) {count (isLeapYear(i) ? 366 : 365);}monthArray[2] isLeapYear(year) ? 29 : 28;for (int i 1; i month; i)count monthArray[i];count dayOfMonth-1;return (count 4) % 7;
}
int stoi_my(const string a) {int r0;for (int i 0; i a.size(); i) {r r * 10 a[i] - 0;}return r;
}
string itos(const int i) {char s[30];sprintf(s, %d, i);return string(s);
}
vectorstring splitStringAndBulidVector(string str, int TAG 0) {//TAG0(other),1(month),2(dayOfWeek)//transform string to vector of the num// 1-12 or 1,2.Split this by , and then split num with -.vectorstring vstring;str ,;size_t found str.find(,);while (found str.find(,),found ! string::npos) {string x str.substr(0, found);str str.substr(found 1, str.size() - found - 1);size_t found2 x.find(-);if (found2 string::npos) {// one number or stringif (TAG 1 isalpha(x[0])) x itos(mMon[x]);if (TAG 2 isalpha(x[0])) x itos(mWeek[x]);if (x.size() 1) {x 0 x;}vstring.push_back(x);}else {//1-2 or jan-feb or mon-fristring a x.substr(0, found2);string b x.substr(found2 1, x.size() - found2 - 1);int l 0, r 0;if (TAG 0) { l stoi_my(a), r stoi_my(b); }else if (TAG 1) {//monthl (isalpha(a[0])) ? mMon[a] : stoi_my(a);r (isalpha(b[0])) ? mMon[b] : stoi_my(b);}else {l (isalpha(a[0])) ? mWeek[a] : stoi_my(a);r (isalpha(b[0])) ? mWeek[b] : stoi_my(b);}while (l r) {string lstr l10?0itos(l):itos(l);vstring.push_back(lstr);l;}}}return vstring;
}int main()
{freopen(in.txt, r, stdin);//get inputsbulidMonAndWeekMap();int n;string st, et;cin n st et;string syy st.substr(0, 4), smm st.substr(4, 2), sdd st.substr(6, 2), sHH st.substr(8, 2), sMM st.substr(10, 2);string eyy et.substr(0, 4), emm et.substr(4, 2), edd et.substr(6, 2), eHH et.substr(8, 2), eMM et.substr(10, 2);int syyInt stoi_my(syy), eyyInt stoi_my(eyy);vectorstring vminute, vhour, vdayOfMonth, vmonth, vdayOfWeek;while (n--) {string minutes, hours, dayOfMonth, month, dayOfWeek, command;cin minutes hours dayOfMonth month dayOfWeek command;standlize(month); standlize(dayOfWeek);//Transform to lower caseif (minutes *)minutes 1-59;vminute splitStringAndBulidVector(minutes);if (hours *)hours 0-23;vhour splitStringAndBulidVector(hours);if (dayOfMonth *)dayOfMonth 1-31;vdayOfMonth splitStringAndBulidVector(dayOfMonth);if (month *)month 1-12;vmonth splitStringAndBulidVector(month, 1);if (dayOfWeek *)dayOfWeek 0-6;vdayOfWeek splitStringAndBulidVector(dayOfWeek, 2);int dayOfWeekArray[7] { 0 };// for quick queryingfill(dayOfWeekArray, dayOfWeekArray 7, 0);for (int i 0; ivdayOfWeek.size(); i)dayOfWeekArray[stoi_my(vdayOfWeek[i])] 1;int curyear syyInt;//Start from syyInt.Do this for each command;while (curyear eyyInt) {monthArray[2] isLeapYear(curyear) ? 29 : 28;string year itos(curyear);//iterator monthfor (vectorstring::iterator mi vmonth.begin(); mivmonth.end(); mi) {for (vectorstring::iterator di vdayOfMonth.begin(); divdayOfMonth.end(); di) {int dayOfWeekInt getDayOfWeek(curyear, stoi_my(*mi), stoi_my(*di));//check whether dayOfWeek is right and dayOfMonth less than Maxif (!dayOfWeekArray[dayOfWeekInt] || (stoi_my(*di))monthArray[stoi_my(*mi)])continue;//iterator hours and minutesfor (vectorstring::iterator hi vhour.begin(); hivhour.end(); hi) {for (vectorstring::iterator mini vminute.begin(); minivminute.end(); mini) {string datetime year *mi *di *hi *mini;if (datetime st datetime et)mrt[datetime].push_back(command);//push command into the vector of this time}}}}curyear;}}//iterator resultsfor (mapstring, vectorstring::iterator it mrt.begin(); it ! mrt.end(); it) {for (vectorstring::iterator rit it-second.begin(); ritit-second.end(); rit) {cout it-first *rit endl;}}return 0;
} 转载于:https://www.cnblogs.com/SilverChen/p/9569536.html