adding cp3

This commit is contained in:
Jidong Xiao
2023-11-05 01:16:09 -04:00
parent 1c30e6f4c8
commit 730c2d1d9d
2 changed files with 56 additions and 3 deletions

View File

@@ -24,9 +24,38 @@ Finally, implement and test the *resize* function. This function is automaticall
**To complete this checkpoint**: Show a TA these additions and the test output.
## Checkpoint 3
## Checkpoint 3: Using std::unordered_map
*estimate: remainder of lab time*
*estimate: 20-30 minutes*
To be added.
Complete the *isHappy* function in this [program](test_happy_number.cpp). This function determines if a number n is happy or not. You can assume 1<=n<50000. Do not include extra libraries.
A happy number is a number defined by the following process:
- Starting with any positive integer, replace the number by the sum of the squares of its digits.
- Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.
- Those numbers for which this process ends in 1 are happy.
Return true if n is a happy number, and false if not. Here are some examples:
```console
Example 1:
Input: n = 19
Output: true
Explanation:
12 + 92 = 82
82 + 22 = 68
62 + 82 = 100
12 + 02 + 02 = 1
```
```console
Example 2:
Input: n = 2
Output: false
```
**To complete this checkpoint**: Show a TA your program and the test results.