90分,实在找不到哪里错了
查看原帖
90分,实在找不到哪里错了
134130
KangPeng楼主2023/9/20 12:45
#include<iostream>
#include<cstdio>
#include<string> 
#include<cmath>
using namespace std;
unsigned long long getNum(int len,unsigned long long N){
	if(N<=len-1 && N>=0)
		return N;
	int p=0;
	unsigned long long temp=len*pow(2,p+1)-1;
	while(temp<N)
	{
		++p;
		temp=len*pow(2,p+1)-1;		
	}
	if(N==len*pow(2,p))//由最后一个字母旋转而来 
		--N;
	else
		N=N-len*pow(2,p)-1; //对应到旋转之前的字母 
	getNum(len,N);
}
int main(){
	string s;
	unsigned long long N;
	cin>>s;
	scanf("%lld",&N);
	printf("%c",s[getNum(s.length(),N-1)]);//N-1是将第N个字母变为索引 
	return 0;
} 

我的思路是不断去找前一次旋转前字母的索引.感谢大佬

2023/9/20 12:45
加载中...