#include #include #include #include #include #include #include #include using namespace std; int main(int *argc, char *argv[]) { cout << "\n\n\t\t ---------------- FLOW ---------------- \n\n\n\n"; ofstream FileWrite; FileWrite.open ("flow.out"); int N = 0; int P = 0; int B = 0; int StartRow[251]; int StartColumn[251]; int EndRow[251]; int EndColumn[251]; int BaseRow[251]; int BaseColumn[251]; int stream_information; int info_counter = 0; int Final_Stream_Information[500]; int path_length = 0; fstream ReadingFile("flow.in", fstream::in); if (ReadingFile.is_open()) { while(ReadingFile >> stream_information) { Final_Stream_Information[info_counter] = stream_information; info_counter = info_counter + 1; } ReadingFile.close(); } else { cout << "flow file, can't be opened"; } N = Final_Stream_Information[0]; P = Final_Stream_Information[1]; if( N < 6 || N > 100 || P < 1 || P > 250) { cout << "\n -> Size of the table can't be smaller than 6 and bigger than 100, please check your file\n"; cout << " -> Count of lakes can't be smaller than 1 and bigger than 250, please check your file\n\n"; } int delay_counter = 0; for(int i = 0; i < P; i++) { for(int j = 2; j <= P*4+1; j++) { if(delay_counter == 1) { delay_counter = 0; i++; j = j + 3; } StartRow[i] = Final_Stream_Information[j]; StartColumn[i] = Final_Stream_Information[j + 1]; EndRow[i] = Final_Stream_Information[j + 2]; EndColumn[i] = Final_Stream_Information[j + 3]; delay_counter++; } } for(int i = 0; i < P; i++) { if(StartRow[i] < 0 || StartRow[i] > N || StartColumn[i] < 0 || StartColumn[i] > N || EndRow[i] < 0 || EndRow[i] > N || EndColumn[i] < 0 || EndColumn[i] > N) { cout << "\n -> Coordinate data can not be smaller than 0 and bigger than the table size for lake [" << i << "], please check your file\n"; cout << "\n -> Please enter new coordinates for lake [" << i << "], please check your file\n"; } } B = Final_Stream_Information[2 + P*4]; if(B < 0 || B > 500) { cout << "\n -> Count of bases can't be smaller than 0 and bigger than 500\n"; } int B_Delay_Counter = 0; for(int i = 0; i < B; i++) { for(int j = P*4+3; j <= info_counter - 1; j++) { if(B_Delay_Counter == 1) { B_Delay_Counter = 0; i++; j = j + 1; } BaseRow[i] = Final_Stream_Information[j]; BaseColumn[i] = Final_Stream_Information[j + 1]; B_Delay_Counter++; } } for(int i = 0; i < B; i++) { if(BaseRow[i] < 0 || BaseRow[i] > N || BaseColumn[i] < 0 || BaseColumn[i] > N) { cout << "\n -> Coordinate data can not be smaller than 0 and bigger than the table size for base [" << i << "], please check your file\n"; cout << "\n -> Please enter new coordinates for base [" << i << "], please check your file\n"; } } cout << "\n\n"; for(int i = 0; i < P; i++) { if(EndColumn[i] < StartColumn[i]) { if(EndRow[i] < StartRow[i]) { path_length = 0; for(int j = EndColumn[i]; j <= StartColumn[i]; j++) { path_length = path_length + 1; } for(int j = EndRow[i] + 1; j <= StartRow[i]; j++) { path_length = path_length + 1; } FileWrite << path_length << " "; for(int j = EndColumn[i]; j <= StartColumn[i]; j++) { FileWrite << EndRow[i] << " " << j << " "; } for(int j = EndRow[i] + 1; j <= StartRow[i]; j++) { FileWrite << j << " " << StartColumn[i] << " "; } FileWrite << "\n"; } else if(EndRow[i] == StartRow[i]) { path_length = 0; for(int j = EndColumn[i]; j <= StartColumn[i]; j++) { path_length = path_length + 1; } FileWrite << path_length << " "; for(int j = EndColumn[i]; j <= StartColumn[i]; j++) { FileWrite << EndRow[i] << " " << j << " "; } FileWrite << "\n"; } else { path_length = 0; for(int j = EndRow[i]; j >= StartRow[i]; j--) { path_length = path_length + 1; } for(int j = EndColumn[i] + 1; j <= StartColumn[i]; j++) { path_length = path_length + 1; } FileWrite << path_length << " "; for(int j = EndRow[i]; j >= StartRow[i]; j--) { FileWrite << j << " " << EndColumn[i] << " "; } for(int j = EndColumn[i] + 1; j <= StartColumn[i]; j++) { FileWrite << StartRow[i] << " " << j << " "; } FileWrite << "\n"; } } else if(EndColumn[i] == StartColumn[i]) { if(EndRow[i] < StartRow[i]) { path_length = 0; for(int j = EndRow[i]; j <= StartRow[i]; j++) { path_length = path_length + 1; } FileWrite << path_length << " "; for(int j = EndRow[i]; j <= StartRow[i]; j++) { FileWrite << j << " " << EndColumn[i] << " "; } FileWrite << "\n"; } else if(EndRow[i] == StartRow[i]) { FileWrite << "1 " << EndRow[i] << " " << EndColumn[i] << " "; FileWrite << "\n"; } else { path_length = 0; for(int j = EndRow[i]; j >= StartRow[i]; j++) { path_length = path_length + 1; } FileWrite << path_length << " "; for(int j = EndRow[i]; j >= StartRow[i]; j++) { FileWrite << j << " " << EndColumn[i] << " "; } FileWrite << "\n"; } } else { if(EndRow[i] < StartRow[i]) { path_length = 0; for(int j = EndColumn[i]; j >= StartColumn[i]; j--) { path_length = path_length + 1; } for(int j = EndRow[i] + 1; j <= StartRow[i]; j++) { path_length = path_length + 1; } FileWrite << path_length << " "; for(int j = EndColumn[i]; j >= StartColumn[i]; j--) { FileWrite << EndRow[i] << " " << j << " "; } for(int j = EndRow[i] + 1; j <= StartRow[i]; j++) { FileWrite << j << " " << StartColumn[i] << " "; } FileWrite << "\n"; } else if(EndRow[i] == StartRow[i]) { path_length = 0; for(int j = EndColumn[i]; j >= StartColumn[i]; j--) { path_length = path_length + 1; } FileWrite << path_length << " "; for(int j = EndColumn[i]; j >= StartColumn[i]; j--) { FileWrite << EndRow[i] << " " << j << " "; } FileWrite << "\n"; } else { path_length = 0; for(int j = EndColumn[i]; j >= StartColumn[i]; j--) { path_length = path_length + 1; } for(int j = EndRow[i] - 1; j >= StartRow[i]; j--) { path_length = path_length + 1; } FileWrite << path_length << " "; for(int j = EndColumn[i]; j >= StartColumn[i]; j--) { FileWrite << EndRow[i] << " " << j << " "; } for(int j = EndRow[i] - 1; j >= StartRow[i]; j--) { FileWrite << j << " " << StartColumn[i] << " "; } FileWrite << "\n"; } } } cout << "- > File successfully read...\n"; cout << "- > File successfully written...\n"; FileWrite.close(); cout << "\n\n\n\n\n"; system ("pause"); return 0;