A - Happy Birthday, Polycarp!
1 second
256 megabytes
standard input
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.
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.
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!的更多相关文章
- cf723c Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...
- codeforces 723C : Polycarp at the Radio
Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...
- Codeforces 723C. Polycarp at the Radio 模拟
C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- 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 ...
- 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 ...
- Polycarp's problems
Polycarp's problems time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforce B. Polycarp and Letters
B. Polycarp and Letters time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- [Codeforces 864B]Polycarp and Letters
Description Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s con ...
- 贪心 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 ...
- Codeforces 861D - Polycarp's phone book
861D - Polycarp's phone book 思路:用map做的话,只能出现一次循环,否则会超时. 代码: #include<bits/stdc++.h> using name ...
随机推荐
- [cf 997 E] Good Subsegments
(这是石神找到的一道hiao题.) 题意: 你有一个长度为n的排列,有Q组询问$[l,r]$,每次询问$[l,r]$的子区间中有多少是好的. 一个区间是好的区间当且仅当该区间中的元素在排序后是连续的. ...
- git 学习笔记 --多人协作
当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 要查看远程库的信息,用git remote: $ git r ...
- Bootstrap中的datetimepicker用法总结
bootstrap时间控件参考文档(少走弯路) https://blog.csdn.net/hizzyzzh/article/details/51212867#31-format-%E6%A0%BC% ...
- C# vb .net实现位图蒙版特效滤镜
在.net中,如何简单快捷地实现Photoshop滤镜组中的位图蒙版特效呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第 ...
- mysql存储过程简单例子
1.之前经常在oracle数据库中使用存储过程,换到mysql后用的不多,但是有时候也用,大致记录一下,基本和oracle的一样. CREATE DEFINER = `root`@`%` PROCED ...
- ASP.NET SignalR 系列(三)之代码实现
说在前头: 因SignalR默认采用camel的编码规范,故前端调用后端的对象或者方法时,首字母均需要小写 创建集线器 创建完,文件中默认创建了一个不带参数Hello方法的示例,我们修改一下,带个参数 ...
- Python Socket Programming UDP/TCP
基于UDP/TCP的套接字编程demo UDP 客户端/服务器 一个简单的基于UDP协议的客户端和服务器应用的进程通信. 逻辑: 客户端会给服务器发送小写的英文字母,服务器接受后,把它转化成大写再返回 ...
- pathlib的使用
目录 一. Python2与Python3的路径处理的对比 二. pathlib的几个使用示例 1. 最简单的使用 2. 追加路径到Python的sys.path中 3. 生成目录树的技巧 4. 递归 ...
- api封装
const sql={ insert: function(collection,insertData){ return new Promise(function(resolve,reject){ co ...
- 【方法整理】Oracle 获取trace跟踪文件名的几种常用方式
[方法整理]Oracle 获取trace跟踪文件名的几种常用方式 1 BLOG文档结构图 2 前言部分 2.1 导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学 ...