NC216039. 2020
描述
输入描述
The first line has one single integer
输出描述
Output the answer
示例1
输入:
34
输出:
3
示例2
输入:
111111
输出:
111
示例3
输入:
777776
输出:
776
示例4
输入:
123413454357678
输出:
9999999
C++(clang++11) 解法, 执行用时: 3ms, 内存消耗: 380K, 提交时间: 2020-12-26 19:55:18
#include<iostream> using namespace std; long long n,ans,pw[19]; int s; int main(){ cin>>n; for(long long i=10;i<=n;i*=10)pw[++s]=i; ++s; if(s&1)cout<<pw[s>>1]-1<<endl; else cout<<(n/pw[s>>1]<=n%pw[s>>1]?n/pw[s>>1]:n/pw[s>>1]-1)<<endl; return 0; }
pypy3(pypy3.6.1) 解法, 执行用时: 51ms, 内存消耗: 25536K, 提交时间: 2021-03-12 22:18:09
n = int(input()) l = 1 r = 10 ** 13 while r - l > 1: mid = (l + r) // 2 s = str(mid) s = s + s if int(s) <= n: l = mid else: r = mid print(l)
Python3(3.9) 解法, 执行用时: 20ms, 内存消耗: 2816K, 提交时间: 2020-12-26 19:03:57
n = int(input()) l = 1 r = 10 ** 12 while r - l > 1: mid = (l + r) // 2 s = str(mid) s = s + s if int(s) <= n: l = mid else: r = mid print(l)