A. Happy Birthday, Polycarp!
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Hooray! Polycarp turned nn years old! The Technocup Team sincerely congratulates Polycarp!

Polycarp celebrated all of his nn birthdays: from the 11-th to the nn-th. At the moment, he is wondering: how many times he turned beautiful number of years?

According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: 11, 7777, 777777, 4444 and 999999999999. The following numbers are not beautiful: 1212, 1111011110, 69696969 and 987654321987654321.

Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).

Help Polycarpus to find the number of numbers from 11 to nn (inclusive) that are beautiful.

Input

The first line contains an integer tt (1≤t≤1041≤t≤104) — the number of test cases in the input. Then tt test cases follow.

Each test case consists of one line, which contains a positive integer nn (1≤n≤1091≤n≤109) — how many years Polycarp has turned.

Output

Print tt integers — the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between 11 and nn, inclusive.

Example

6
18
1
9
100500
33
1000000000

 output

10
1
9
45
12
81

  题目地址:https://codeforces.com/contest/1277/problem/A

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int t,n;
int z[10]={0,1,2,3,4,5,6,7,8,9};
int b[15];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int ans=0;
for(int i=1;i<=9;i++){
long long int x=i;
while(x<=n)//枚举iii…i<=n
{
ans++;
x=10*x+i;
}
}
printf("%d\n",ans);
}
return 0;
}

  

A - Happy Birthday, Polycarp!的更多相关文章

  1. cf723c Polycarp at the Radio

    Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...

  2. codeforces 723C : Polycarp at the Radio

    Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...

  3. Codeforces 723C. Polycarp at the Radio 模拟

    C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  4. Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心

    C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集

    题目链接: 题目 F. Polycarp and Hay time limit per test: 4 seconds memory limit per test: 512 megabytes inp ...

  6. Polycarp's problems

    Polycarp's problems time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforce B. Polycarp and Letters

    B. Polycarp and Letters time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. [Codeforces 864B]Polycarp and Letters

    Description Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s con ...

  9. 贪心 C - Polycarp's New Job

    Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even sto ...

  10. Codeforces 861D - Polycarp's phone book

    861D - Polycarp's phone book 思路:用map做的话,只能出现一次循环,否则会超时. 代码: #include<bits/stdc++.h> using name ...

随机推荐

  1. Python2 和 Python3区别

    字符串类型不同 py3: str bytes py2: unicode str 默认解释器编码 输入输出 int int long 除法 range和xrang 模块和包 字典 keys py2:列表 ...

  2. Maven的仓库和settings.xml配置文件

    (尊重劳动成果,转载请注明出处:https://blog.csdn.net/qq_25827845/article/details/83549846冷血之心的博客) 快速导航: Maven基础概念和安 ...

  3. AutoCAD ObjectARX 二次开发(2020版)--3,执行ARX文件--

    上一节中我们在initApp()函数中,将helloWorld()函数注册给了CAD主程序,注册指令的字符串为“Hello”. void initApp() { acedRegCmds->add ...

  4. ssm动态sql语句

    1.将上面的元素分为四组来演示,分别为:[if,where,trim],[if,set,trim],[choose,when,otherwise],[foreach] ________________ ...

  5. C# vb .net实现宝丽来效果滤镜

    在.net中,如何简单快捷地实现Photoshop滤镜组中的宝丽来效果呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第一 ...

  6. Java自学-类和对象 构造方法

    怎么使用 Java 构造方法? 通过一个类创建一个对象,这个过程叫做实例化 实例化是通过调用构造方法(又叫做构造器)实现的 步骤 1 : 什么是构造方法 方法名和类名一样(包括大小写) 没有返回类型 ...

  7. 在Linux系统中创建SSH服务器别名

    如果你经常通过 SSH 访问许多不同的远程系统,这个技巧将为你节省一些时间.你可以通过 SSH 为频繁访问的系统创建 SSH 别名,这样你就不必记住所有不同的用户名.主机名.SSH 端口号和 IP 地 ...

  8. Python的bytes和str

    Python和C的字符串 在Python 3 中,bytes单独作为一个类型,不再和str类型混在一起.关于字符串和字节,我想先回顾下C/C++ 在C/C++中,字符串是由char数组构成,每个元素是 ...

  9. Vue v-bind与v-model的区别

    v-bind    缩写 : 动态地绑定一个或多个特性,或一个组件 prop 到表达式. 官网举例   <!-- 绑定一个属性 -->   <img v-bind:src=" ...

  10. loadrunner通过字符串左右边界提取字符串

    /****** *函数名称:strcut *函数说明:通过左边界.右边界,从字符串中截取子字符串 *注意事项:会申请新的内存,需要手动释放 ******/ void strcut(char *strS ...