/* Autore */ // Assume file di input e file di output non malformati. #include #include #include #include #include #include using namespace std; ifstream *fin; ifstream *fcor; ifstream *fout; void ex(const char *msg, float res) { if(msg) { fprintf(stderr, "%s ", msg); } printf("%f\n", res); exit(0); } template T safe_read(const T &lowerBound, const T &upperBound) { // Legge in maniera sicura un tipo ordinato e controlla che stia in // [lowerBound, upperBound] T x; if (lowerBound > upperBound) { cerr << "safe_read chiamato con parametri errati: " << lowerBound << " " << upperBound << "\n"; return 1; } *fout >> x; if (fout->fail()) ex("Output malformato", 0.0f); if (x < lowerBound || x > upperBound) ex("Output invalido", 0.0f); return x; } void check_fine_file() { string x; if (fout->eof()) return; *fout >> x; if (x != "" || !fout->eof()) ex("Output malformato", 0.0f); } int N,M; int cor_first_value; int out_first_value; vector > edges; vector initial_match; vector alt_match; vector inv_alt_match; bool distinct_match = false; int main(int argc, char *argv[]) { if(argc < 4) { cerr << "Usage: " << argv[0] << " " << endl; return 1; } fin = new ifstream(argv[1]); fcor = new ifstream(argv[2]); fout = new ifstream(argv[3]); if(fin->fail()) { cerr << "Impossibile aprire il file di input " << argv[1] << "." << endl; return 1; } if(fcor->fail()) { cerr << "Impossibile aprire il file di output corretto " << argv[2] << "." << endl; return 1; } if(fout->fail()) ex("Impossibile aprire il file di output generato dal codice sottoposto al problema.", 0.0); *fin >> N >> M; initial_match.resize(N); edges.resize(N); for(int i=0; i> src >> dst; edges[src].insert(dst); if(i> cor_first_value; out_first_value = safe_read(-1, N-1); if(out_first_value == -1) { check_fine_file(); if(cor_first_value != -1) ex("Nessun matching restituito.", 0.0f); else ex("Corretto.", 1.0f); } alt_match.resize(N, -1); inv_alt_match.resize(N, -1); for(int i=0;i