算法刷题记录:珂朵莉的假toptree
题目链接
https://ac.nowcoder.com/acm/contest/19306/1035
题目分析
将每个数每一位都进行拆分即可。
AC代码
#include <iostream>
using namespace std;
int n, p = 1, num = 1;
int a[1005];
int main()
{
cin >> n;
while (p <= 1000)
{
if (num >= 1000) a[p ++ ] = num / 1000;
if (num >= 100) a[p ++ ] = num / 100 % 10;
if (num >= 10) a[p ++ ] = num / 10 % 10;
a[ p ++ ] = num % 10;
num ++ ;
}
cout << a[n];
}
AC代码
字符串有时候真的是神器!
#include <iostream>
using namespace std;
int n, p = 1, num = 1;
string a = "0";
int main()
{
cin >> n;
for (int i = 1; i <= 1000; ++ i)
a += to_string(i);
cout << a[n];
}
本文来自博客园,作者:想个昵称好难ABCD,转载请注明原文链接:https://www.cnblogs.com/ClockParadox43/p/17439641.html