//----------------------------------------------------------------------- // File: prob.cpp // Description: Calculate distance between 2 family names // Author: Chau-Wen Tseng (tseng@cs.umd.edu) //----------------------------------------------------------------------- #include #include #include // Uncomment the following lines if using APCS classes // #include "apvector.h" // #include "apmatrix.h" // #include "apstack.h" // #include "apqueue.h" #include "apstring.cpp" //----------------------------------------------------------------------- // calcDist() - calculates distance between 2 hobbit names //----------------------------------------------------------------------- double calcDist(apstring x, apstring y) { const int MISMATCH_PENALTY = 50; // penalty for mismatch const int TRUNCATE_PENALTY = 4; // penalty for missing letter const double SCALE_FACTOR = 0.90; // scaling factor for later positions ////////// BEGIN your code ////////////// return 0.0; ////////// END your code ////////////// } //----------------------------------------------------------------------- // main //----------------------------------------------------------------------- int main() { const int MAXLEN = 50; apstring names[MAXLEN]; double dist[MAXLEN][MAXLEN]; int families; int i,j; // read in family names, should be in alphabetical order cin >> families; for (i = 0; i < families; i++) { cin >> names[i]; if ((i > 0) && (names[i] < names[i-1])) { cout << "ERROR: name " << names[i] << " not in alphabetical order!" << endl; ; } } // calculate distance for every pair of family names for (i = 0; i < families; i++) { for (j = i+1; j < families; j++) { dist[i][j] = calcDist(names[i], names[j]); } } // output distance between pairs of family names in alphabetical order cout.setf(ios::showpoint); // show trailing decimal places cout << families << endl; for (i = 0; i < families; i++) { for (j = i+1; j < families; j++) { cout << dist[i][j] << " " << names[i] << " " << names[j] << endl; } } return 0; }