public void DocFile(string duongDan) { StreamReader sr = new StreamReader(duongDan); int soLuong = int.Parse(sr.ReadLine()); Mays = new MayMoc[soLuong]; for (int i = 0; i < soLuong; i++) { Mays[i] = new MayMoc(sr.ReadLine()); } soLuong = int.Parse(sr.ReadLine()); CongViecs = new CongViec[soLuong]; for (int i = 0; i < soLuong; i++) { string[] dong = sr.ReadLine().Split(' '); CongViecs[i] = new CongViec(dong[0], int.Parse(dong[1])); } sr.Close(); }
public void XuLiPhanCong() { //Sap xep cong viec theo thu tu giam dan ve thoi gian for (int i = 0; i < CongViecs.Length - 1; i++) { for (int j = i + 1; j < CongViecs.Length; j++) { if (CongViecs[i].ThoiGianThucHien < CongViecs[j].ThoiGianThucHien) { CongViec tam = CongViecs[i]; CongViecs[i] = CongViecs[j]; CongViecs[j] = tam; } } } int thuTuCongViec = 0; for (int i = 0; i < Mays.Length; i++) { if (Mays[i].CacCongViecs.Count == 0) { Mays[i].ThemCongViec(CongViecs[thuTuCongViec]); thuTuCongViec++; } } //Tim may nao co tong thoi gian lam viec it nhat roi quang cong viec vao for (; thuTuCongViec < CongViecs.Length; thuTuCongViec++) { int viTriMayCoCongViecItNhat = 0; int min = Mays[0].TongThoiGian; for (int i = 0; i < Mays.Length; i++) { if (Mays[i].TongThoiGian < min) { min = Mays[i].TongThoiGian; viTriMayCoCongViecItNhat = i; } } Mays[viTriMayCoCongViecItNhat].ThemCongViec(CongViecs[thuTuCongViec]); } }
public void ThemCongViec(CongViec a) { CacCongViecs.Add(a); TongThoiGian += a.ThoiGianThucHien; }