10分P3612

P3612 [USACO17JAN] Secret Cow Code S

sb458hhhhhhh @ 2024-10-04 23:26:04


#include<iostream>
#include<string>
using namespace std;
long long n;
string str;
long long fun(long long x,long long p,int len)
{
    if(x <= len)
    {
        return x;
    }
    if(x == p / 2 + 1)
    {
        x = x - 1;
        p/=2;
    }
    else
    {
        x = (x - 1) - (p / 2);
        p/=2;
    }
    return fun(x,p,len);
}
int main()
{
    cin>>str;
    cin>>n;
    long long p = str.length();
    while(p < n)
    {
        p = p * 2;
    }
    cout<<str[fun(n,p,str.length()) - 1];
    return 0;
}

by sb458hhhhhhh @ 2024-10-04 23:43:39

调好了,不用回复了


|