思路和题解一样的,用的递归,但是RE和WA了

P3612 [USACO17JAN] Secret Cow Code S

金钢猪 @ 2021-02-02 14:38:52

#include<stdio.h>
#include<string.h>
long long n;
long long length,len;
char s[35];

void slove(long long leng,long long nth){
    if(nth <= len){
        printf("%c",s[nth-1]);
        return ;
    }

    long long half = leng/2;
    long long new_nth = nth-half-1;
    slove(half,new_nth);
}

int main(){
    scanf("%s",s);
    scanf("%lld",&n);
    len = strlen(s);
    length = len;
    while(length < n){
        length*=2;
    }
    slove(length,n);
    return 0;
} 

by 金钢猪 @ 2021-02-02 14:39:47

加入0特判断的情况还是一样的


|