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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值