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 ...
随机推荐
- DRF框架(三)——media资源路径设置、多表设计复习及补充、序列化组件(ModelSerializer)操作多表(序列化与反序列化)、多表序列化与反序列化整合(重点)
media资源路径设置 (设置好后把图片放在这个文件夹中,通过链接能访问到图片) 1.先在根目录设置一个media文件夹 2.配置settings.py,加上下面的 MEDIA_URL = '/me ...
- 带小伙伴手写 golang context
前言 - context 源码 可以先了解官方 context.go 轮廓. 这里捎带保存一份当前 context 版本备份. // Copyright 2014 The Go Authors. Al ...
- 【题解】Luogu P5361 [SDOI2019]热闹又尴尬的聚会
原题传送门 构造题. 明显p,q都越大越好 我们考虑每次取出度最小的点,加到尴尬聚会的集合中(因为把与它相邻的点全删了,不珂能出现认识的情况),把它自己和与自己相连的点从图上删掉(边也删掉),记下这个 ...
- Fluentdata详解
Fluentdata 轻型orm 仅仅一个cs文件 创建并且初始化一个IDbContext. 二选一 public IDbContext Context() { return new DbContex ...
- 学习网络BGP必备基础知识
外部网关协议,使用TCP作为传输层协议,支持CIDR,增量更新,距离矢量路由协议,无环路,路由策略丰富,可防止路由震荡,易于扩展. BGP概述 #BGP工作原理 之 报文类型 TCP三次握手 open ...
- 浏览器Notwork XHR被隐藏了
图片中红色区域内容被隐藏 解决方式,点击此处
- JAVA基础之JSP与EL技术、JSTL技术
要牢记jsp四大作用域(pageContext域:当前jsp页面范围 request域:一次请求 session域:一次会话 application域:整个web应用)以及九大内置对 ...
- Oracle 用户与模式的关系
一.用户登录 Oracle 数据库的安全保护流程分为3个步骤. 1.用户向数据库提供身份识别信息,即提供一个数据库账号 2.证明身份识别信息是否有效,通过密码来实现 3.用户输入的密码经过数据库的核对 ...
- 房地产propretie财产
property 1. 财产:所有物(不可数); 地产, 房地产 He has a large property in the county. 他在这个县有一大宗地产. 1.Propretie obs ...
- Xcode调试打印方法
1 NSLog 在调试的过程中,最常用的查看变量值的方法是NSLog 整数 int a = 1; NSLog("%d", a); 浮点数 float b = 1.11; NSLog ...