在给定的进制下,将C++中的Pandigital数字翻译成中文

2023年 8月 30日 47.6k 0

在给定的进制下,将C++中的Pandigital数字翻译成中文

包含从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]

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论