Created
February 15, 2017 15:10
-
-
Save LouiseBC/815dc0b44f27a10118959325934b5c39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| int giveMeFive(const int& a, const int& b) | |
| { | |
| int containsFive = 0; | |
| for (int i = a; i <= b; ++i) { | |
| std::string number = std::to_string(i); | |
| for (auto ch : number) { | |
| if (ch == '5') { | |
| ++containsFive; | |
| break; | |
| } | |
| } | |
| } | |
| return (b-a)-containsFive + 1; | |
| } | |
| int main() | |
| { | |
| std::cout << giveMeFive(-10, 0) << std::endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment