Let’s call a positive integer 𝑛 ordinary if in the decimal notation
all its digits are the same. For example, 1, 2 and 99 are ordinary
numbers, but 719 and 2021 are not ordinary numbers.For a given number 𝑛, find the number of ordinary numbers among the
numbers from 1 to 𝑛.Input The first line contains one integer 𝑡 (1≤𝑡≤104). Then 𝑡 test
cases follow.Each test case is characterized by one integer 𝑛 (1≤𝑛≤109).
Output For each test case output the number of ordinary numbers among
numbers from 1 to 𝑛.Example inputCopy 6 1 2 3 4 5 100 outputCopy 1 2 3 4 5 18
#include<iostream>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int count=0;
for(int i=1;i<=9;i++)
{
long long temp=i;
while(n>=temp)
{
count++;
temp=temp*10+i;
}
}
printf("%d\n",count);
}
}