Skip to content

Instantly share code, notes, and snippets.

@LouiseBC
Created February 15, 2017 15:10
Show Gist options
  • Select an option

  • Save LouiseBC/815dc0b44f27a10118959325934b5c39 to your computer and use it in GitHub Desktop.

Select an option

Save LouiseBC/815dc0b44f27a10118959325934b5c39 to your computer and use it in GitHub Desktop.
#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