Skip to content

Commit

Permalink
fixed bug pass 11.36's requesting
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Dec 18, 2014
1 parent 313d011 commit 3290700
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 87 deletions.
19 changes: 19 additions & 0 deletions ch11/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,22 @@ std::pair<std::map<std::string, std::vector<int>>::iterator, bool> // return
## [Exercise 11.31](ex11_31.cpp)
## [Exercise 11.32](ex11_32.cpp)
## [Exercise 11.33](ex11_33.cpp)

## Exercise 11.34:
>What would happen if we used the subscript operator instead of find in the transform function?
If the subscript operator was used instead, it would add the given key into the map when no element with matching key was found.

## Exercise 11.35:
>In buildMap, what effect, if any, would there be from rewriting `trans_map[key] = value.substr(1);` as `trans_map.insert({key, value.substr(1)})`?
- use subscript operator: if a word does appear multiple times, our loops will put the **last** corresponding phrase into trans_map
- use `insert`: if a word does appear multiple times, our loops will put the **first** corresponding phrase into trans_map

## Exercise 11.36:
>Our program does no checking on the validity of either input file. In particular, it assumes that the rules in the transformation file are all sensible.
What would happen if a line in that file has a key, one space, and then the end of the line? Predict the behavior and then check it against your version of the program.

we added a file that name "word_transformation_bad.txt" to folder `data`. the file only has a key, one space.

the program of 11.33 don't influenced by that.
2 changes: 1 addition & 1 deletion ch11/ex11_33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void word_transform(ifstream &map, ifstream &input)

int main()
{
ifstream ifs_map("../data/word_transformation.txt"), ifs_content("../data/given_to_transform.txt");
ifstream ifs_map("../data/word_transformation_bad.txt"), ifs_content("../data/given_to_transform.txt");
if (ifs_map && ifs_content) word_transform(ifs_map, ifs_content);
else std::cerr << "can't find the documents." << std::endl;
}
86 changes: 0 additions & 86 deletions ch11/ex11_34_35_36.cpp

This file was deleted.

1 change: 1 addition & 0 deletions data/word_transformation_bad.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
l8r

0 comments on commit 3290700

Please sign in to comment.