首页 > 试题广场 >

无限长正整数排列字符串

[编程题]无限长正整数排列字符串
  • 热度指数:165 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}定义无限字符串 S=\texttt{,即将所有正整数依次拼接得到。
\hspace{15pt}珂朵莉想知道该字符串的第 n 个字符是什么。

输入描述:
\hspace{15pt}在一行中输入一个整数 n \left(1 \leqq n \leqq 1000\right)


输出描述:
\hspace{15pt}输出一个数字,表示字符串 S 的第 n 个字符。
示例1

输入

3

输出

3

说明

n=3 时,S=\texttt{,其第 3 个字符为 \texttt{'3'}
示例2

输入

11

输出

0

说明

n=11 时,S=\texttt{,其第 11 个字符为 \texttt{'0'}

备注:

头像 Hanson_Zhong
发表于 2022-05-13 16:35:16
链接:https://ac.nowcoder.com/acm/contest/19306/1035 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 珂朵莉想求12345678910 展开全文
头像 GB279824
发表于 2025-06-08 14:18:08
s = int(input().strip()) def find_pos(s): if s <= 9: return str(s) elif s <= 189: s -= 9 index = (s-1) // 2 展开全文
头像 ciallobit
发表于 2025-05-31 11:28:17
n = int(input()) s = "" for i in range(1, n + 1): s += str(i) print(s[n - 1]) 不用枚举,时间复杂度O(n)
头像 冷意
发表于 2025-06-03 23:43:25
#include <iostream> #include <string> using namespace std; int findNthDigit(int n) { int digits = 1; // 当前数字位数 long long count = 展开全文

问题信息

上传者:牛客301599号
难度:
1条回答 41浏览

热门推荐

通过挑战的用户

查看代码
无限长正整数排列字符串