Check whether given string contains all the digits from 0 to 9
Here given code implementation process.
// C Program for
// Check whether given string contains all the digits from 0 to 9
#include <stdio.h>
#include <string.h>
void digitZeroToNine(char *text)
{
int n = strlen(text);
printf("\n Given text : %s ", text);
int count[10];
// Initial each digit count is zero
for (int i = 0; i < 10; ++i)
{
count[i] = 0;
}
// Count frequency of character element
for (int i = 0; i < n; ++i)
{
if (text[i] >= '0' && text[i] <= '9')
{
// Means digit exist
count[text[i] - '0'] = 1;
}
}
// Check all digits existence
for (int i = 0; i < 10; ++i)
{
if (count[i] == 0)
{
// When digit missing
printf("\n No ");
return;
}
}
// When all digits exist
printf("\n Yes ");
}
int main(int argc, char
const *argv[])
{
digitZeroToNine("All534Happy2021bonus987613");
// Missing 1
digitZeroToNine("Error3235467854690found");
digitZeroToNine("125322379232654580");
return 0;
}
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
// Java program for
// Check whether given string contains all the digits from 0 to 9
public class DigitCheck
{
public void digitZeroToNine(String text)
{
int n = text.length();
System.out.print("\n Given text : " + text);
int[] count = new int[10];
// Initial each digit count is zero
for (int i = 0; i < 10; ++i)
{
count[i] = 0;
}
// Count frequency of character element
for (int i = 0; i < n; ++i)
{
if (text.charAt(i) >= '0' && text.charAt(i) <= '9')
{
// Means digit exist
count[text.charAt(i) - '0'] = 1;
}
}
// Check all digits existence
for (int i = 0; i < 10; ++i)
{
if (count[i] == 0)
{
// When digit missing
System.out.print("\n No ");
return;
}
}
// When all digits exist
System.out.print("\n Yes ");
}
public static void main(String[] args)
{
DigitCheck task = new DigitCheck();
// Test
task.digitZeroToNine("All534Happy2021bonus987613");
// Missing 1
task.digitZeroToNine("Error3235467854690found");
task.digitZeroToNine("125322379232654580");
}
}
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
// Include header file
#include <iostream>
#include <string>
using namespace std;
// C++ program for
// Check whether given string contains all the digits from 0 to 9
class DigitCheck
{
public: void digitZeroToNine(string text)
{
int n = text.length();
cout << "\n Given text : " << text;
int count[10];
// Initial each digit count is zero
for (int i = 0; i < 10; ++i)
{
count[i] = 0;
}
// Count frequency of character element
for (int i = 0; i < n; ++i)
{
if (text[i] >= '0' && text[i] <= '9')
{
// Means digit exist
count[text[i] - '0'] = 1;
}
}
// Check all digits existence
for (int i = 0; i < 10; ++i)
{
if (count[i] == 0)
{
// When digit missing
cout << "\n No ";
return;
}
}
// When all digits exist
cout << "\n Yes ";
}
};
int main()
{
DigitCheck *task = new DigitCheck();
// Test
task->digitZeroToNine("All534Happy2021bonus987613");
// Missing 1
task->digitZeroToNine("Error3235467854690found");
task->digitZeroToNine("125322379232654580");
return 0;
}
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
package main
import "fmt"
// Go program for
// Check whether given string contains all the digits from 0 to 9
type DigitCheck struct {}
func getDigitCheck() * DigitCheck {
var me *DigitCheck = &DigitCheck {}
return me
}
func(this DigitCheck) digitZeroToNine(text string) {
var n int = len(text)
fmt.Print("\n Given text : ", text)
var count = make([] int, 10)
// Initial each digit count is zero
for i := 0 ; i < 10 ; i++ {
count[i] = 0
}
// Count frequency of character element
for i := 0 ; i < n ; i++ {
if text[i] >= '0' && text[i] <= '9' {
// Means digit exist
count[text[i] - '0'] = 1
}
}
// Check all digits existence
for i := 0 ; i < 10 ; i++ {
if count[i] == 0 {
// When digit missing
fmt.Print("\n No ")
return
}
}
// When all digits exist
fmt.Print("\n Yes ")
}
func main() {
var task * DigitCheck = getDigitCheck()
// Test
task.digitZeroToNine("All534Happy2021bonus987613")
// Missing 1
task.digitZeroToNine("Error3235467854690found")
task.digitZeroToNine("125322379232654580")
}
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
// Include namespace system
using System;
// Csharp program for
// Check whether given string contains all the digits from 0 to 9
public class DigitCheck
{
public void digitZeroToNine(String text)
{
int n = text.Length;
Console.Write("\n Given text : " + text);
int[] count = new int[10];
// Initial each digit count is zero
for (int i = 0; i < 10; ++i)
{
count[i] = 0;
}
// Count frequency of character element
for (int i = 0; i < n; ++i)
{
if (text[i] >= '0' && text[i] <= '9')
{
// Means digit exist
count[text[i] - '0'] = 1;
}
}
// Check all digits existence
for (int i = 0; i < 10; ++i)
{
if (count[i] == 0)
{
// When digit missing
Console.Write("\n No ");
return;
}
}
// When all digits exist
Console.Write("\n Yes ");
}
public static void Main(String[] args)
{
DigitCheck task = new DigitCheck();
// Test
task.digitZeroToNine("All534Happy2021bonus987613");
// Missing 1
task.digitZeroToNine("Error3235467854690found");
task.digitZeroToNine("125322379232654580");
}
}
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
<?php
// Php program for
// Check whether given string contains all the digits from 0 to 9
class DigitCheck
{
public function digitZeroToNine($text)
{
$n = strlen($text);
echo("\n Given text : ".$text);
$count = array_fill(0, 10, 0);
// Count frequency of character element
for ($i = 0; $i < $n; ++$i)
{
if ($text[$i] >= '0' && $text[$i] <= '9')
{
// Means digit exist
$count[ord($text[$i]) - ord('0')] = 1;
}
}
// Check all digits existence
for ($i = 0; $i < 10; ++$i)
{
if ($count[$i] == 0)
{
// When digit missing
echo("\n No ");
return;
}
}
// When all digits exist
echo("\n Yes ");
}
}
function main()
{
$task = new DigitCheck();
// Test
$task->digitZeroToNine("All534Happy2021bonus987613");
// Missing 1
$task->digitZeroToNine("Error3235467854690found");
$task->digitZeroToNine("125322379232654580");
}
main();
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
// Node JS program for
// Check whether given string contains all the digits from 0 to 9
class DigitCheck
{
digitZeroToNine(text)
{
var n = text.length;
process.stdout.write("\n Given text : " + text);
var count = Array(10).fill(0);
// Count frequency of character element
for (var i = 0; i < n; ++i)
{
if (text.charAt(i) >= '0' && text.charAt(i) <= '9')
{
// Means digit exist
count[text.charCodeAt(i) - '0'.charCodeAt(0)] = 1;
}
}
// Check all digits existence
for (var i = 0; i < 10; ++i)
{
if (count[i] == 0)
{
// When digit missing
process.stdout.write("\n No ");
return;
}
}
// When all digits exist
process.stdout.write("\n Yes ");
}
}
function main()
{
var task = new DigitCheck();
// Test
task.digitZeroToNine("All534Happy2021bonus987613");
// Missing 1
task.digitZeroToNine("Error3235467854690found");
task.digitZeroToNine("125322379232654580");
}
main();
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
# Python 3 program for
# Check whether given string contains all the digits from 0 to 9
class DigitCheck :
def digitZeroToNine(self, text) :
n = len(text)
print("\n Given text : ", text, end = "")
count = [0] * (10)
i = 0
# Count frequency of character element
while (i < n) :
if (text[i] >= '0'
and text[i] <= '9') :
# Means digit exist
count[ord(text[i]) - ord('0')] = 1
i += 1
i = 0
# Check all digits existence
while (i < 10) :
if (count[i] == 0) :
# When digit missing
print("\n No ", end = "")
return
i += 1
# When all digits exist
print("\n Yes ", end = "")
def main() :
task = DigitCheck()
# Test
task.digitZeroToNine("All534Happy2021bonus987613")
# Missing 1
task.digitZeroToNine("Error3235467854690found")
task.digitZeroToNine("125322379232654580")
if __name__ == "__main__": main()
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
# Ruby program for
# Check whether given string contains all the digits from 0 to 9
class DigitCheck
def digitZeroToNine(text)
n = text.length
print("\n Given text : ", text)
count = Array.new(10) {0}
i = 0
# Count frequency of character element
while (i < n)
if (text[i] >= '0' && text[i] <= '9')
# Means digit exist
count[text[i].ord - '0'.ord] = 1
end
i += 1
end
i = 0
# Check all digits existence
while (i < 10)
if (count[i] == 0)
# When digit missing
print("\n No ")
return
end
i += 1
end
# When all digits exist
print("\n Yes ")
end
end
def main()
task = DigitCheck.new()
# Test
task.digitZeroToNine("All534Happy2021bonus987613")
# Missing 1
task.digitZeroToNine("Error3235467854690found")
task.digitZeroToNine("125322379232654580")
end
main()
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
import scala.collection.mutable._;
// Scala program for
// Check whether given string contains all the digits from 0 to 9
class DigitCheck()
{
def digitZeroToNine(text: String): Unit = {
var n: Int = text.length();
print("\n Given text : " + text);
var count: Array[Int] = Array.fill[Int](10)(0);
var i: Int = 0;
// Count frequency of character element
while (i < n)
{
if (text.charAt(i) >= '0' && text.charAt(i) <= '9')
{
// Means digit exist
count(text.charAt(i).toInt - '0'.toInt) = 1;
}
i += 1;
}
i = 0;
// Check all digits existence
while (i < 10)
{
if (count(i) == 0)
{
// When digit missing
print("\n No ");
return;
}
i += 1;
}
// When all digits exist
print("\n Yes ");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: DigitCheck = new DigitCheck();
// Test
task.digitZeroToNine("All534Happy2021bonus987613");
// Missing 1
task.digitZeroToNine("Error3235467854690found");
task.digitZeroToNine("125322379232654580");
}
}
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
import Foundation;
// Swift 4 program for
// Check whether given string contains all the digits from 0 to 9
class DigitCheck
{
func digitZeroToNine(_ data: String)
{
let text = Array(data);
let n: Int = text.count;
print("\n Given text : ", data, terminator: "");
var count: [Int] = Array(repeating: 0, count: 10);
var i: Int = 0;
// Count frequency of character element
while (i < n)
{
if (text[i] >= "0" && text[i] <= "9")
{
// Means digit exist
count[Int(UnicodeScalar(String(text[i]))!.value) -
Int(UnicodeScalar(String("0"))!.value)] = 1;
}
i += 1;
}
i = 0;
// Check all digits existence
while (i < 10)
{
if (count[i] == 0)
{
// When digit missing
print("\n No ", terminator: "");
return;
}
i += 1;
}
// When all digits exist
print("\n Yes ", terminator: "");
}
}
func main()
{
let task: DigitCheck = DigitCheck();
// Test
task.digitZeroToNine("All534Happy2021bonus987613");
// Missing 1
task.digitZeroToNine("Error3235467854690found");
task.digitZeroToNine("125322379232654580");
}
main();
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
// Kotlin program for
// Check whether given string contains all the digits from 0 to 9
class DigitCheck
{
fun digitZeroToNine(text: String): Unit
{
val n: Int = text.length;
print("\n Given text : " + text);
val count: Array < Int > = Array(10)
{
0
};
var i: Int = 0;
// Count frequency of character element
while (i < n)
{
if (text.get(i) >= '0' && text.get(i) <= '9')
{
// Means digit exist
count[text.get(i).toInt() - '0'.toInt()] = 1;
}
i += 1;
}
i = 0;
// Check all digits existence
while (i < 10)
{
if (count[i] == 0)
{
// When digit missing
print("\n No ");
return;
}
i += 1;
}
// When all digits exist
print("\n Yes ");
}
}
fun main(args: Array < String > ): Unit
{
val task: DigitCheck = DigitCheck();
// Test
task.digitZeroToNine("All534Happy2021bonus987613");
// Missing 1
task.digitZeroToNine("Error3235467854690found");
task.digitZeroToNine("125322379232654580");
}
Output
Given text : All534Happy2021bonus987613
Yes
Given text : Error3235467854690found
No
Given text : 125322379232654580
Yes
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment