题目描述
在输的页码中找到某个数字是第一次出现。比如数字1,分别在页码:1、10,11,12中出现。那么数字1第五次出现在12页;第3和4次出现在第11页。
输入
一行两个整数k和n。代表要找的数字和出现的次数。
输出
一行,数字出现的页码
样例输入
1 5
样例输出
12
以下是代码:
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
int main() {
int n, r;
cin >> n >> r;
int cnt = 0;
int sum = 0;
while (sum < r) {
cnt++;//页码加1
int y = cnt;//当前页码等于页码
// 检查当前页码中的每一位数字
while (y > 0) //当前页码>0执行
{
if (y % 10 == n) //遍历查找
{
sum++;
if (sum == r)
{
cout << cnt << endl;
}
}
y /= 10;
}
}
return 0;
}