📜  门| GATE CS 2021 |设置 2 |问题 12(1)

📅  最后修改于: 2023-12-03 15:28:39.119000             🧑  作者: Mango

GATE CS 2021 | Setting 2 | Question 12

Introduction

This is a programming question that was asked in the GATE CS 2021 examination. The question aims to test the programming skills of the candidates.

Problem Statement

The question asks the candidates to write a program that takes two integers as input, a and b. The program should output the number of integers in the range [a, b] (inclusive) that have the digit 0 in their decimal representation.

Approach
  • Firstly, we need to take two integers a and b as input.
  • Then we need to iterate over the range [a, b] (inclusive) and for each integer in the range, we need to check if it has the digit 0 in its decimal representation.
  • If it does, we increment a counter variable.
  • Finally, we output the counter variable.

Here is the code snippet in Python:

a, b = map(int, input().split())

count = 0

for num in range(a, b+1):
    if '0' in str(num):
        count += 1

print(count)
Explanation
  • In the code above, we first take two integers a and b as input using the input() function and split them using the split() function.
  • We then map each value to an integer using the map() function and assign them to the variables a and b.
  • We then initialize a counter variable count to 0.
  • Next, we iterate over the range [a, b] (inclusive) using the range() function.
  • For each integer num in the range, we check if it contains the digit 0 in its decimal representation.
  • If it does, we increment the count variable.
  • Finally, we output the value of count.
Conclusion

In conclusion, this programming question from the GATE CS 2021 examination tests the candidate's programming skills. The solution involves taking two integers as input and iterating over a range to count the number of integers with the digit 0 in their decimal representation.