【无标题】

#E、 消失的零

描述

有一个无限长的正整数序列:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20…1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20…

调皮的小明把该序列中所有包含00的数字都删掉了!于是这个正整数序列就变成了:

1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,21…1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,21…

现在,请你编程输出该序列的第nn个数。

输入

第一行是一个正整数TT代表测试案例的数量。

每组案例是一个正整数nn。

输出

针对每组案例,在一行中输出该序列的第nn个数。

样例输入

  1. 2
  2. 1
  3. 20

样例输出

  1. 1
  2. 22

python:

T = int(input())
for _ in range(T):
    n = int(input())
    count = 0
    num = 1
    while count < n:
        if '0' not in str(num):
            count += 1
        num += 1
    print(num - 1)

c++:

#include <bits/stdc++.h>
using namespace std;

int findNthNumber(int n) {
    int count = 0;
    int num = 1;
    while (count < n) {
        int temp = num;
        bool hasZero = false;
        while (temp > 0) {
            if (temp % 10 == 0) {
                hasZero = true;
                break;
            }
            temp /= 10;
        }
        if (!hasZero) {
            count++;
        }
        num++;
    }
    return num - 1;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        cout << findNthNumber(n) << endl;
    }
    return 0;
}

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值