根据大学课程表管理时间的工具,放一个源码
#include<iostream> #include<fstream> #include<string> #include<ctime> #include<algorithm> #include<queue> #define WINDOWS using namespace std; int B_DAY, B_DATE; int now_date, now_day; string table[15][15], view[15][15]; int Ecnt, Pcnt, occ[15][15]; struct Event { int DATE, P; string name; bool operator < (const Event &A) const { return DATE == A.DATE ? P < A.P : DATE < A.DATE; } }es[1005], prob[1005]; priority_queue<Event > q; ifstream In("settings.txt"); ofstream Out; void clean() { #ifdef WINDOWS system("cls"); #endif #ifdef LINUX system("clear"); #endif } void Red() { #ifdef WINDOWS system("COLOR 04"); #endif #ifdef LINUX system("\033[31m"); #endif } void Green() { #ifdef WINDOWS system("COLOR 02"); #endif #ifdef LINUX system("\033[32m"); #endif } void Blue() { #ifdef WINDOWS system("COLOR 01"); #endif #ifdef LINUX system("\033[34m"); #endif } void Org() { #ifdef WINDOWS system("COLOR 07"); #endif #ifdef LINUX system("\033[39m"); #endif } void load() { Pcnt = Ecnt = 0; In >> B_DATE >> B_DAY; now_day = ((now_date - B_DATE) + B_DAY) % 7; for(register int i = 0; i < 7; ++i) { for(register int j = 1; j <= 6; ++j) { In >> table[i][j]; if(table[i][j] != "空") occ[i][j] = -1; view[i][j] = table[i][j]; } } int c; In >> c; int d, p;string s; for(register int i = 1; i <= c; ++i) { In >> d >> p >> s; if(d < now_date) continue; ++Ecnt; es[Ecnt].DATE = d, es[Ecnt].P = p, es[Ecnt].name = s; if(d - now_date > 6) continue; view[(d - now_date + now_day) % 7][p] = s; occ[(d - now_date + now_day) % 7][p] = Ecnt; } In >> c; for(register int i = 1; i <= c; ++i) { In >> d >> p >> s; if(d < now_date) continue; ++Pcnt; prob[Pcnt].DATE = d, prob[Pcnt].P = p, prob[Pcnt].name = s; } sort(prob + 1, prob + 1 + Pcnt); } void save() { Out.open("settings.txt"); Out << B_DATE << " " << B_DAY << endl; for(register int i = 0; i < 7; ++i) { for(register int j = 1; j <= 6; ++j) Out << table[i][j] << " "; Out << endl; } Out << Ecnt << endl; for(register int i = 1; i <= Ecnt; ++i) { Out << es[i].DATE << " " << es[i].P << " " << es[i].name << endl; } Out << Pcnt << endl; for(register int i = 1; i <= Pcnt; ++i) { Out << prob[i].DATE << " " << prob[i].P << " " << prob[i].name << endl; } Out.close(); } void Show() { puts("##"); for(register int i = 0; i < 7; ++i) printf("%12d", i); puts(""); for(register int i = 0; i < 7; ++i) printf("%12d", (i + now_day) % 7 + 1); puts(""); for(register int j = 1; j <= 6; ++j) { if(j == 3) { for(register int i = 0; i < 7; ++i) printf("%12s", "------"); puts(""); } for(register int i = 0; i < 7; ++i) { printf("%12s", view[(i + now_day) % 7][j].c_str()); } puts(""); } printf("一次性事件:\n"); for(register int i = 1; i <= Ecnt; ++i) { cout << i << " : "<< es[i].name << endl; } printf("可安排事件:\n"); for(register int i = 1; i <= Pcnt; ++i) { cout << i << " : "<< prob[i].name << endl; } } void ALLC() { int pos = 1; for(register int i = 0; i < 7; ++i) { for(register int j = 1; j <= 6; ++j) { if(occ[(i + now_day) % 7][j]) continue; if(pos <= Pcnt) { view[(i + now_day) % 7][j] = prob[pos++].name; } else { view[(i + now_day) % 7][j] = "空"; } } } } int Init; void init() { Org(); int t = time(0), tmp; now_date = t / (24 * 60 * 60); if(Init || !In.is_open()) { cout << "您好,欢迎使用时间管理大师" << endl; cout << "第一次使用,请您输入今天是星期几(1~7) : "; cin >> B_DAY; B_DATE = now_date, --B_DAY; printf("现在输入课程表:\n"); for(register int i = 0; i < 7; ++i) { for(register int j = 1; j <= 6; ++j) { printf("你星期%d的第%d节安排是:(没有填\"空\",小于10个字)", i + 1, j); cin >> table[i][j]; } } save(); In.open("settings.txt"); Init = 0; } load(); } int main() { init(); string op, s, msg; int a, b, c; while(1) { ALLC(); Show(); cout << "反馈区:" << endl; if(msg != "") { cout << msg << endl; msg = ""; } cout << "请输入操作:" << endl; cin >> op; if(op == "rp") { cin >> a; if(a >= 1 && a <= Pcnt) { for(register int i = a; i <= Pcnt; ++i) prob[i] = prob[i + 1]; Pcnt--; } else {msg = "操作失败!";} save(); } if(op == "re") { cin >> a; if(a >= 1 && a <= Ecnt) { occ[(es[a].DATE - now_date + now_day) % 7][es[a].P] = 0; for(register int i = a; i <= Ecnt; ++i) es[i] = es[i + 1]; Ecnt--; } else {msg = "操作失败!";} save(); } if(op == "e") { scanf("%d%d", &a, &b); cin >> s; if(a < 0 || a > 6 || b > 6 || b < 1) {msg = "操作失败!";} else { view[a - 1][b] = table[a - 1][b] = s; if(s == "空") occ[a - 1][b] = 0; else occ[a - 1][b] = -1; save(); } } if(op == "ae") { scanf("%d%d", &a, &b); cin >> s; if(b > 6 || b < 1) {msg = "操作失败!";} else { es[++Ecnt] = (Event) {a + now_date, b, s}; if(a <= 6) { occ[(a + now_day) % 7][b] = -1; view[(a + now_day) % 7][b] = s; } save(); } } if(op == "ap") { scanf("%d%d", &a, &b); cin >> s; if(b > 6 || b < 1) {msg = "操作失败!";} else { prob[++Pcnt] = (Event) {a + now_date, b, s}; sort(prob + 1, prob + Pcnt + 1); save(); } } if(op == "ip") { cin >> s; prob[++Pcnt] = (Event) {99999999, 0, s}; sort(prob + 1, prob + Pcnt + 1); save(); } if(op == "init") { Init = 1, init(); } if(op == "?" || op == "help") { msg = "ae x y 名字 : 在x天后第y节课添加一个一次性事件"; msg += (op = "\n"); msg += (op = "ap x y 名字 : 添加x天后的第y节截止的可安排事件"); msg += (op = "\n"); msg += op = "ip 名字 : 添加一个不限时事件"; msg += (op = "\n"); msg += op = "re id : 删除一个一次性事件,id是它显示的编号"; msg += (op = "\n"); msg += op = "rp id : 删除一个可安排事件,id是它显示的编号"; msg += (op = "\n"); msg += op = "e x y s : 把课表星期x的第y节改为s课(s可以为\"空\")"; msg += (op = "\n"); msg += op = "init : 初始化所有设置"; msg += (op = "\n"); } clean(); } return 0; }
没有帐号? 立即注册