下载下来样例 我的代码没有错啊,没啥通过不了?
查看原帖
下载下来样例 我的代码没有错啊,没啥通过不了?
524191
Man_CCNU楼主2022/1/7 20:48
#include<iostream>

using namespace std;

const int N=1e6 + 10;

long long int a[N],n,idx;
string s;

long long int  findS(long long int i)
{
    int j = 1;
    for (j = 1; j <= idx; j++) {
        if (a[j] > i) break;
    }

    return j;
}
long long int  pro(int step,long long int i)
{
    if (i <= s.size()) return i;
    auto len_ = a[step - 1];
    if (i > len_) {
        i -= len_;
        i--;
        if (i == 0) i = len_;
        return pro(step - 1, i);
    }
    else {
        step = findS(i);
        return pro(step, i);
    }
}
int main()
{
    cin >> s;
    cin >> n;
    a[++idx] = s.size();
    while (a[idx] < n) {
        a[++idx] = a[idx - 1] + a[idx - 1];
    }
    cout << s[pro(idx, n) - 1] << endl;

    return 0;
}
2022/1/7 20:48
加载中...