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. day52——jquery引入与下载、标签查找、操作标签

    day52 jquery引入 下载链接:jQuery官网 https://jquery.com/ 中文文档:jQuery AP中文文档 http://jquery.cuishifeng.cn/ < ...

  2. Python爬虫之旅(一):小白也能懂的爬虫入门

    Python爬虫之旅(一):小白也能懂的爬虫入门   爬虫是什么 爬虫就是按照一定的规则,去抓取网页中的信息.爬虫流程大致分为以下几步: 向目标网页发送请求 获取请求的响应内容 按照一定的规则解析返回 ...

  3. .net Dapper 实践系列(4) ---数据查询(Layui+Ajax+Dapper+MySQL)

    写在前面 上一小节,总结了数据显示时,会出现的日期问题.以及如何处理格式化日期.这个小节,主要总结的是使用Dapper 中的QueryMultiple方法依次显示查询多表的数据. 实践步骤 1.在Bo ...

  4. C#实现RSA加密解密

    RSA介绍 RSA公钥加密算法是1977年由Ron Rivest、Adi Shamirh和LenAdleman在(美国麻省理工学院)开发的。RSA取名来自开发他们三者的名字。 RSA的缺点: 产生密钥 ...

  5. C# vb .net实现过度曝光效果滤镜

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

  6. 读取txt文件的数据,并将其转换为矩阵

    import numpy as nppath_txt_data = 'C:/Users/51102/Desktop/my_yolo/data/box/train.txt'def input_data( ...

  7. 【开发工具】- Atom下载及安装

    原文地址:https://www.jianshu.com/p/c112f024e0ab

  8. FIneUICore 版本的 AppBoxMvcCore

    http://www.51aspx.com/code/codename/64088 CORE版本的APPBOXMVC欢迎下载

  9. linux上安装redis-单机版

    1. Redis的安装 1.1. Redis的安装 Redis是c语言开发的. 安装redis需要c语言的编译环境.如果没有gcc需要在线安装.yum install gcc-c++ 安装步骤: 第一 ...

  10. scrapy 爬虫中间件 deepth深度

    源码 class DepthMiddleware(object): def __init__(self, maxdepth, stats, verbose_stats=False, prio=1): ...