包含从0到基数B的所有数字的数字称为该基数下的全数字数。然而,一些数字的数字从1到9,被称为无零全数字数。一些全数字数的例子包括0123456789,0789564312等。
在本教程中,我们将讨论一个问题,我们给定一个数字和一个基数,我们需要检查该数字在给定基数下是否为全数字数,例如−
Input: num = “9651723467380AZ”, base = 10
Output: YES
Explanation: num contains all the digits in the base 10 i.e from 0 to 9, so it is a pandigital number.
Input: num = “130264ABCDE745789”, base = 16
Output: NO
Explanation: num does not contain F(15) which is in the base 16 i.e from 0 to 15, so it is not a pandigital number.
登录后复制
Approach to Find the Solution
To solve this problem, we will use Set and insert each digit in the set because we need to store unique values.
-
Traverse through the string, taking each character at a time.
-
Then check if the element is an integer or alphabet.
-
If it is an alphabet, then add 10 to its position on the alphabet to represent 2-digit.
-
Store the values in the set.
-
After traversing, check whether the size of the set equals to base.
Example
C++ Code for the Above Approach
#include
using namespace std;
int main(){
int base = 10;
char n[] = "9651723467380AZ";
// Declaring set to store unique values.
set s;
// Traversing through the string.
for (int i = 0; i = '0' && n[i]