生活随笔
收集整理的這篇文章主要介紹了
排课软件(拓扑排序)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
要求:程序接收輸入的課程總數,專業,以及每個課程的各種信息(課程號,課程名,任課老師名等),課程之間的先修關系,沒門課程開始的開課時間。
根據拓撲排序后的課程先修關系進行排刻,使用MFC界面顯示排課信息,并使用MFC控件進行查詢。
程序沒寫的不太完善,就以拓撲排序為中心寫的。UI界面用的是VS的MFC寫的,挺丑的,就不弄上來了。程序總體也就是3個函數,寫的挺簡單。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#define maxn 100
using namespace std
;
struct node
{char cno
[maxn
]; char cname
[maxn
];char tea
[maxn
];int wtime
; int ttime
;
};
vector
<node
> course
[maxn
];
queue
<int> s
;
int view
[maxn
];
int ak
[maxn
];
int numbera
;
void shuru()
{int i
,j
;printf("總課程數:\n");cin
>>numbera
;node ke
;printf("輸入每個課程號,課程名,任課老師:\n");for(i
=1; i
<=numbera
; i
++) {printf("第%d門課:",i
);cin
>>ke
.cno
>>ke
.cname
>>ke
.tea
;course
[i
].push_back(ke
);}for(i
=1; i
<=numbera
; i
++){printf(" %s的先修課程: \n", course
[i
][0].cno
);string a
;cin
>>a
;while(a
[0]!='#'){for(j
=1; j
<=numbera
; j
++){if(a
==course
[j
][0].cno
)break;}course
[i
].push_back(course
[j
][0]);cin
>>a
;}}
}
void shuchu()
{int i
,j
;memset(view
,0,sizeof(view
));printf("每個課程的極其先修課:\n");for(i
=1; i
<=numbera
; i
++) printf("%s ",course
[i
][0].cno
);printf("\n");for(i
=1; i
<=numbera
; i
++){printf("%s",course
[i
][0].cno
);for(j
=1; j
<course
[i
].size(); j
++)printf("->%s",course
[i
][j
].cno
);cout
<<" "<<course
[i
].size()-1<<endl
;view
[i
]=course
[i
].size()-1;}
}
void tuopu()
{int num
=1;for (int i
=1; i
<=numbera
; i
++)if(view
[i
]==0){s
.push(i
);view
[i
]=-1;}while(!s
.empty()){int a
=s
.front();s
.pop();ak
[num
]=a
;num
++;for(int i
=1; i
<=numbera
; i
++){for(int j
=1; j
<course
[i
].size(); j
++){string a1
=course
[i
][j
].cno
;string a2
=course
[a
][0].cno
;if(a1
==a2
){view
[i
]--;}}}for(int i
=1; i
<=numbera
; i
++)if(view
[i
]==0){s
.push(i
);view
[i
]=-1;}}printf("排課順序:\n");printf("課程號 課程名 授課老師\n");for(int i
=1; i
<=numbera
; i
++){cout
<<course
[ak
[i
]][0].cno
<<" "<<course
[ak
[i
]][0].cname
<<" "<<course
[ak
[i
]][0].tea
<<endl
;}}int main()
{freopen("1.txt","r",stdin);shuru();shuchu();tuopu();return 0;
}
freopen內容
12
c1 課程設計基礎 teacherA
c2 離散數學 teacherB
c3 數據結構 teacherC
c4 匯編語言 teacherD
c5 語言的設計和分析 teacherE
c6 計算機原理 teacher12F
c7 編譯原理 teacherG
c8 操作系統 teacherH
c9 高等數學 teacherI
c10 線性代數 teacherJ
c11 普通物理 teacherK
c12 數值分析 teacherL
#
c1 #
c1 c2 #
c1 #
c3 #
c11 #
c5 c3 #
c3 c6 #
#
c9 #
c9 #
c9 c10 c1 #
結果(多余的輸出自己看情況修改)
排課順序:
課程號 課程名 授課老師
c1 課程設計基礎 teacherA
c9 高等數學 teacherI
c2 離散數學 teacherB
c4 匯編語言 teacherD
c10 線性代數 teacherJ
c11 普通物理 teacherK
c3 數據結構 teacherC
c12 數值分析 teacherL
c6 計算機原理 teacher12F
c5 語言的設計和分析 teacherE
c8 操作系統 teacherH
c7 編譯原理 teacherG
總結
以上是生活随笔為你收集整理的排课软件(拓扑排序)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。