A. Strange Functions
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Let's define a function f(x)f(x) (xx is a positive integer) as follows: write all digits of the decimal representation of xx backwards, then get rid of the leading zeroes. For example, f(321)=123f(321)=123, f(120)=21f(120)=21, f(1000000)=1f(1000000)=1, f(111)=111f(111)=111.
Let's define another function g(x)=xf(f(x))g(x)=xf(f(x)) (xx is a positive integer as well).
Your task is the following: for the given positive integer nn, calculate the number of different values of g(x)g(x) among all numbers xx such that 1≤x≤n1≤x≤n.
Input
The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.
Each test case consists of one line containing one integer nn (1≤n<101001≤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)g(x), if xx can be any integer from [1,n][1,n].
Example
input
Copy
5 4 37 998244353 1000000007 12345678901337426966631415output
Copy
1 2 9 10 26Note
Explanations for the two first test cases of the example:
- if n=4n=4, then for every integer xx such that 1≤x≤n1≤x≤n, xf(f(x))=1xf(f(x))=1;
- if n=37n=37, then for some integers xx such that 1≤x≤n1≤x≤n, xf(f(x))=1xf(f(x))=1 (for example, if x=23x=23, f(f(x))=23f(f(x))=23,xf(f(x))=1xf(f(x))=1); and for other values of xx, xf(f(x))=10xf(f(x))=10 (for example, if x=30x=30, f(f(x))=3f(f(x))=3, xf(f(x))=10xf(f(x))=10). So, there are two different values of g(x)g(x).
题意
让我们来定义两个函数
f(x)(x是个正数):把x翻转并去掉反转后的前导0.
例如:f(123) = 321,f(110) = 11,f(3000000) = 3,f(333) = 333.
g(x) = x / f(f(x)),x同样也是一个正数.
你现在的任务是给你一个正数 n ,计算出所有 g(x) 不同函数值的个数, 1 <= x <= n;Input
第一行为 t ,代表接下来会有 t 组数据
接下来 t 行每行一个数字 n ,1 ≤ n < 10^100 (10的一百次方,数据保证 n 没有前导零.
Output
输出:
对于每输入的一个数字 **n **,请输出所有 g(x) 不同函数值的个数, 1 <= x <= n;
Example
input:
5
3
12345
1000000007
996
12345678901337426966631415output:
1
5
10
3
26Note
1:对于 3 来说,可能的 g(x) = {1};
2: 对于996 来说,可能的 g(x) = {1,10,100}; g(x) == 10 仅当 x == 10;g(x) == 100 仅当 x == 100.Sponsor
读题可知,找前导0的种类再+1(1的情况)
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
char a[10001] = { 0 };
cin >> a;
int bit = strlen(a);
cout << bit << endl;
}
return 0;
}