the order
This commit is contained in:
@@ -168,7 +168,7 @@ When users run this command:
|
||||
nynotifications.exe posts.json users.json events_medium.txt output.txt taylorswift
|
||||
```
|
||||
|
||||
your program should produce an output which contains notifications which should be delivered to taylorswift.
|
||||
your program should produce an output which contains notifications which should be delivered to taylorswift. The notifications should stay in the same order as the corresponding event appears in the events file. In other words, let's say event A triggers notification A, and event B triggers notification B, and event A occurs before event B, then notification A should be printed in the output file before notification B.
|
||||
|
||||
The format of these notification messages should be similar to (but not identical to) what Instagram does:
|
||||
|
||||
@@ -200,7 +200,7 @@ For messageRequest notifications:
|
||||
|
||||
### getline
|
||||
|
||||
**Note**: this next paragraph is the same as that paragraph in homework 8, and you are once again recommended to read the whole file into a large string; but if you want to beat Jidong on the leaderboard, whether or not this is the most efficient way to read the file is a question for you to think about.
|
||||
**Note**: this next paragraph is the same as that paragraph in homework 8 and homework 9, and for the two json files we use in this assignment, you are once again recommended to read the whole file into a large string; but if you want to beat Jidong on the leaderboard, whether or not this is the most efficient way to read the file is a question for you to think about.
|
||||
|
||||
Unlike previous assignments where the input files only contain fields separated by spaces, in this assignment, fields are not separated by spaces, and therefore you may need a different way to read the input files. And the function *getline* will now come into play. To read the json file and store the whole json file into a std::string, you can use the following lines of code:
|
||||
|
||||
@@ -223,39 +223,6 @@ Unlike previous assignments where the input files only contain fields separated
|
||||
|
||||
After these lines, the whole content of the json file will be stored as a string in the std::string variable *json_content*. And you can then parse it to get each individual post. In order to parse the *json_content*, which is a std::string, you will once again find that the std::string functions such as *std::string::find*(), and *std::string::substr*() to be very useful.
|
||||
|
||||
### Extract Hashtags from the Post Text
|
||||
|
||||
Assume you store the post text content in a std::string variable called *text*, the following code block will extract all hashtags from this text string.
|
||||
|
||||
```cpp
|
||||
// the text of the post is given as a std::string, extract hashtags from the text.
|
||||
|
||||
// define a regular expression to match hashtags
|
||||
std::regex hashtagRegex("#([\\w\\u0080-\\uFFFF]+)");
|
||||
|
||||
// create an iterator for matching
|
||||
std::sregex_iterator hashtagIterator(text.begin(), text.end(), hashtagRegex);
|
||||
std::sregex_iterator endIterator;
|
||||
|
||||
// iterate over the matches and extract the hashtags
|
||||
while (hashtagIterator != endIterator) {
|
||||
std::smatch match = *hashtagIterator;
|
||||
std::string hashtag = match.str(1); // extract the first capturing group
|
||||
// this line will print each hash tag
|
||||
// if you want to do more with each hash tag, do it here. for example, store all hash tags in your container.
|
||||
std::cout << "Hashtag: " << hashtag << std::endl;
|
||||
|
||||
++hashtagIterator;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In order to use this above code block, you need to include the regular expression library like this:
|
||||
|
||||
```cpp
|
||||
#include <regex>
|
||||
```
|
||||
|
||||
## Program Requirements & Submission Details
|
||||
|
||||
In this assignment, you can use any other data structures we have already learned, such as std::string, std::vector, std::list, std::map, std::set, std::pair, std::unordered_map, std::unordered_set, std::stack, std::queue, std::priority_queue. **You must use try/throw/catch to handle exceptions in your code**. You do not need to do so everywhere in your code. You will only lose points if you do not use it at all.
|
||||
|
||||
Reference in New Issue
Block a user