Codeforces 1277A Happy Birthday, Polycarp!

题目链接:

1277A Happy Birthday, Polycarp!

思路:

1.*位数有9个符合要求的,设我们求出给定的数字是xx位,那一定有(x1)9(x-1)*9个数符合要求;
2.接下来判断xx位数里有多少符合要求即可;

代码:

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
#define fi first
#define sc second
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pt(a) cerr<<a<<"---\n"
#define rp(i,n) for(int i=0;i<n;i++)
#define rpn(i,n) for(int i=1;i<=n;i++)
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t; cin>>t;
	while(t--){
		string s; cin>>s;
		int ans=0;
		ans+=(s.length()-1)*9;
		ans+=s[0]-'0'-1;
		string ss="";
		for(int i=0;i<s.length();i++) ss+=s[0];
		if(s>=ss) ans++;
		cout<<ans<<'\n';
	}
	return 0;
}
posted @ 2019-12-21 17:56  YuhanのBlog  阅读(118)  评论(0编辑  收藏  举报