{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

23S-CS106X-Practice-Key

# 23S-CS106X-Practice-Key - CS106X Autumn 2009 Handout 23S...

This preview shows pages 1–2. Sign up to view the full content.

CS106X Handout 23S Autumn 2009 October 28 th , 2009 CS106X Practice Solution Solution 1: Acronyms void ReadIntoMap(ifstream& in, Map<Vector<string> >& map) { Scanner s; s.setSpaceOption(Scanner::IgnoreSpaces); while (true) { string line; getline(in, line); if (in.fail()) break; s.setInput(line); string acronym = ""; while (s.hasMoreTokens()) acronym += s.nextToken()[0]; map[acronym].add(line); // [] creates empty vector if needed } } double PercentConfusing(Map<Vector<string> >& map) { Map<Vector<string> >::Iterator itr = map.iterator(); int numConfusing = 0; while (itr.hasNext()) { string key = itr.next(); if (map[key].size() > 1) numConfusing++; } return double(numConfusing)/map.size(); } Solution 2: Pascal’s Travels int NumPaths(Grid<int>& board) { return NumPaths(board, 0, 0); } int NumPaths(Grid<int>& board, int row, int col) { if ((row == board.numRows() – 1) && (col == board.numCols() – 1)) return 1; if (!OnBoard(board, row, col)) return 0; if (board[row][col] == 0) return 0; int hop = board[row][col]; board[row][col] = 0;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern