算法刷题记录:珂朵莉的假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];
}
posted @ 2023-05-29 10:03  想个昵称好难ABCD  阅读(18)  评论(0编辑  收藏  举报