mirror of
https://bitbucket.org/Mattrixwv/my-classes.git
synced 2025-12-06 18:23:57 -05:00
Added isPandigital function
This commit is contained in:
@@ -19,8 +19,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef MEE_STRING_ALGORITHMS_HPP
|
#pragma once
|
||||||
#define MEE_STRING_ALGORITHMS_HPP
|
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -111,7 +110,26 @@ bool isPalindrome(std::string str){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//This function returns true if the string passed to it is a pandigital
|
||||||
|
bool isPandigital(std::string str, char bottom, char top){
|
||||||
|
//Return false if the wrong number of characters are in the string
|
||||||
|
if(str.size() != (top - bottom + 1)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Make sure that all of the needed characters are in the string exactly one time
|
||||||
|
for(char cnt = bottom;cnt <= top;++cnt){
|
||||||
|
//If a single character is found more than once then the string is not pandigital
|
||||||
|
if(findNumOccurrence(str, cnt) != 1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//If the function has reached this part it has passed all of the falsifying tests
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool isPandigital(std::string str){
|
||||||
|
return isPandigital(str, '1', '9');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
#endif //MEE_STRING_ALGORITHMS_HPP
|
|
||||||
|
|||||||
Reference in New Issue
Block a user