29-CS106X-Midterm

29-CS106X-Midterm - p CS106X Winter 2008 Handout 29 CS106X...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
p CS106X Handout 29 Winter 2008 February 19, 2008 CS106X Midterm Examination This is an open-note, open-book, open-course-reader exam. You can refer to any course handouts, handwritten lecture notes, and printouts of any code relevant to a CS106X assignment. You may not use any laptops, cell phones, or handheld devices of any sort. You have exactly three hours to complete this exam. Anyone taking the exam remotely can call in to ask questions: 415-205-2242. Remote exam takers should fax their exams to 415-358-4942 and hold on to the original until it’s clear the fax was complete and legible. Good luck! Section Leader: _____________________ Last Name: _____________________ First Name: _____________________ I accept the letter and spirit of the honor code. I’ve neither given nor received aid on this exam. I pledge to write more neatly than I ever have in my entire life. (signed) __________________________________________________________ Score Grader 1. Banned Substrings (10) ______ ______ 2. The 70 2 Puzzle (10) ______ ______ 3. SparseStringVector (20) ______ ______ Total (40) ______ ______ SCPD students who want their exams sent back through regular mail, check here: _____
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Problem 1: Sanitizing Strings (10 points) Write a recursive procedure called Sanitize , which takes a string of text and a Vector<string> of banned substrings and returns the shortest string that can be generated by eliminating all illegal substrings. For instance, if the only banned substring is abc , then the string babaabcbcc can be sanitized down to b , via: babaabc bcc bababc c babc b Note that each string in the stack is the same at the one above it, except that the underlined substrings have been spliced out. A more elaborate example illustrates that baacabacaaabcaaabbaa can be edited down to baa if the set of banned substrings includes ac , ab , and caa , as illustrated by: baacabacaaabcaaab baa baacab acaaabcaabaa baacacaa abcaabaa baacaa bcaabaa baabcaaba a baab caaa bacaa a baa Write a recursive procedure called Sanitize that computes and returns the smallest string that can be generated by an optimal series of substring eliminations. Recall that the string ’s find method searches the receiving string from start forward and returns the smallest index where substring can be found (or string::npos if substring isn’t present.) int string::find(string substring, int start = 0); Use the next page for your answer.
Background image of page 2
/** * Function: Sanitize * ------------------ * Accepts the specified string and the collection * of banned substrings, and returns the smallest string * that can be generated by the optimal application of * substring eliminations. */ string Sanitize(string str, Vector<string>& substrings)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/18/2008 for the course CS 106X taught by Professor Cain,g during the Winter '08 term at Stanford.

Page1 / 10

29-CS106X-Midterm - p CS106X Winter 2008 Handout 29 CS106X...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online