CS 106X Study Guide - Midterm Guide: Big O Notation, Unit Testing, Edge Case
Document Summary
Based on autumn 2017 cs 106x midterm exam solutions. Copyright stanford university, nick troccoli, licensed under creative commons attribution 2. 5 license. All rights reserved: code reading mystery("oxidize") after : "eiidxzo" return: 3 mystery("tcttcgtccgaaccaga") after : "acacccaccagtgttgt" return: 10, code reading, o(n2, o(n, o(n log n, o(n2) Every code-writing problem can be solved in multiple ways. Map ratios; int totalcitycount = 0; int totalvotecount = 0; // read the district data from the file string line; while (getline(file, line)) { // read the data about one district istringstream input(line); // "district1 a b a a b" string district; input >> district; totalcitycount++; // count the votes and figure out the winning majority party string party; string maxparty = ""; Map votecountscity; while (input >> party) { totalvotecount++; votecountscity[party]++; votecountstotal[party]++; if (maxparty == "" || votecountscity[party] > votecountscity[maxparty]) { maxparty = party; majoritypartycount[maxparty]++; // compute the gerrymandering ratio for each party for (string party : votecountstotal) {