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. Data-Structure-Notes

    Data Structure Notes Chapter-1 Sorting Algorithm Selection Sorting: /* * Selection Sort */ template& ...

  2. C指针的一些小细节

    1  int *c;*c=4-->int *c;int b;c=&b;*c=4; 在使用指针之前,一定要将其初始化,当然,如果是赋予一个地址,就相当于使用的同时就进行了初始化.

  3. git 学习笔记---操作标签

    如果标签打错了,也可以删除: $ git tag -d v0.1 Deleted tag 'v0.1' (was f15b0dd) 因为创建的标签都只存储在本地,不会自动推送到远程.所以,打错的标签可 ...

  4. Kibana访问报错

    浏览器访问提示:Kibana server is not ready yet 查看日志如下 {"type":"log","@timestamp&quo ...

  5. 移动端开发rem布局之less+媒体查询布局的原理步骤和心得

    rem即是以html文件中font-size的大小的倍数rem布局的原理:通过媒体查询设置不同屏幕宽度下的html的font-size大小,然后在css布局时用rem单位取代px,从而实现页面元素大小 ...

  6. 如何导出UML图片以及小人的组件在哪里

    首先先要创建一个新项目 接着在右侧栏目创建一个modal 添加usecase,里面就有小人的组件(注意:是Add Diagram) 将做好的图进行保存程jpg格式(快捷键 ctrl +shift+D) ...

  7. NSMutableArray 删除可变数组元素

    平时使用 NSMutableArray 中经常用到遍历删除数组元素的问题.一般第一个想法是使用一下 forin 就解决了,但是老司机都会知道使用 forin 做删除操作的时候会 crash.报错的原因 ...

  8. PYTHON 文件读写、坐标寻址、查找替换

    读文件 打开文件(文件需要存在) #打开文件 f = open("data.txt","r") #设置文件对象 print(f)#文件句柄 f.close() ...

  9. tp5中在where中使用in

    $where = array(); $where['id'] = array('in', $uid_str); $res = $this->db2->name('user')->wh ...

  10. SSH SSL TELNET的比较(转)

    转载链接  https://blog.csdn.net/baidu_39486224/article/details/81295701 SSL(Secure Sockets Layer (SSL) a ...