나는 직업들 간의 역관계를 찾으려고 노력해왔다. 좀 더 구체적으로 예를 들어 설명하겠습니다.작업 간의 역 관계를 찾는 방법은 무엇입니까?
내가 n 개의 작업을 가지고 있다고 가정하면 {0,1,2,3,4,...n}
입니다. 나는 또한 직업들 사이의 관계가있다. 후임 작업 만 알면 2
다음에 4,5
이옵니다. 5
다음에 7,8
등이옵니다. 텍스트 파일에 있습니다. 나는 일 사이 선행 관계를 obtering (5
의 전임자 일은 무엇인가?) 싶다.
텍스트 출력이 좋을 것입니다. 코드가 있지만 작동하지 않습니다.
ID Successor1 Successor2 Successor3
1 2 3 4
2 6 11 15
3 7 8 13
4 5 9 10
5 20
6 30
7 27
8 12 19 27
9 14
10 16 25
11 20 26
12 14
13 17 18
14 17
15 25
16 21 22
17 22
18 20 22
19 24 29
20 23 25
21 28
22 23
23 24
24 30
25 30
26 31
27 28
28 31
29 32
30 32
31 32
출력 이런 식으로 뭔가해야한다 : 여기
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
#define TOTAL_ACTIVITY 123
void readFile();
void change();
void writeFile();
struct Activity {
int precedessor [3];
int successor [3];
int id;
};
Activity activityList[TOTAL_ACTIVITY];
void main() {
readFile();
change();
writeFile();
}
void readFile() {
ifstream myReadFile;
myReadFile.open("pre.txt");
if (!myReadFile) { //check whether the file can be opened
cerr << "Unable to open file"; // terminate with error
}
while (!myReadFile.eof()) {
int Id,suc1, suc2, suc3;
int t = 0;
while (myReadFile >> Id >> suc1 >> suc2 >> suc3) //data should be in this order
{
activityList[t].id = Id;
activityList[t].successor [0] = suc1;
activityList[t].successor [1] = suc2;
activityList[t].successor [2] = suc3;
t++;
}
}
return;
}
void change() {
int act;
for (int i=1;i<TOTAL_ACTIVITY;i++){
for (int j=0;j<TOTAL_ACTIVITY;j++){
for (int k=0;k<3;k++) {
if (activityList[j].successor[k]==i;)
}
}
}
}
void writeFile() {
ofstream out("out.txt");
out << "id\t" << "Pre1\t" << "Pre2\t" << "Pre3\t"<<"\n";
for (int j = 0; j < TOTAL_ACTIVITY; j++) {
out << activityList[j].id << "\t";
out << activityList[j].precedessor[0]<< "\t";
out << activityList[j].precedessor[1] << "\t";
out << activityList[j].precedessor[2] << "\t";
out << "\n";
}
out.close();
}
은 샘플 입력 당신은 작업의 후계자를 부여
Id Predecesor1 Predecesor2 Predecesor3
........................................
...........................................
...........................................
더 나은 예를 들어 줄 필요가 있습니다. 예상 출력과 함께 예제 파일을 게시하십시오. –
확인. 어떻게하면 txt 파일을 추가 할 수 있습니까? – furkan
FYI'void main()'이 올바르지 않습니다. C 나 C++ 모두 마찬가지입니다. –