Educational Codeforces Round 99 ------Strange Functions

题目

Let’s define a function f(x) (x is a positive integer) as follows: write all digits of the decimal representation of x backwards, then get rid of the leading zeroes. For example, f(321)=123, f(120)=21, f(1000000)=1, f(111)=111.
Let’s define another function g(x)=xf(f(x)) (x is a positive integer as well).
Your task is the following: for the given positive integer n, calculate the number of different values of g(x) among all numbers x such that 1≤x≤n.

Input
The first line contains one integer t (1≤t≤100) — the number of test cases.
Each test case consists of one line containing one integer n (1≤n<10100). This integer is given without leading zeroes.

Output
For each test case, print one integer — the number of different values of the function g(x), if x can be any integer from [1,n].

题解

读题可发现,反转之后只有两种情况,有前导0和没有前导0
当没有前导0时,g(x) = 1
当有前导0时,假设前导0的个数为n,则g(x) = 10^ n
就比如10, 20, 30,,,100以内的整10数他们的结果g(x)都是10
1000以内的整百数g(x)都是100
所以不同结果的个数即答案为改数字的数位,即这个数字是几位数

AC代码

#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--) {
		string str; cin >> str;
		cout << str.length() << endl;
	}
	return 0;
}
上一篇:Spark开发-Spark和UDTF之间的介绍


下一篇:Flink开发_Flink的SQL和TableAPI的UDF