#include <bits/stdc++.h>
using namespace std;
int main (){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int t1=s.find('(');
	int t2=s.find(')');
	string f;
	for(int i=t1+1;i<t2;i++){
		f=f+s[i];
	} 
	int a=t1+1;
	int dian=s.find('.');
	int shuchang=t1-dian-1;
	if(n<=shuchang){
		cout<<s[n+dian];
	}else {
		int p=(n-shuchang)%(t2-t1);
		cout<<f[p];
	}
//	cout<<endl<<f; 
	return 0;
} 

1 条评论

  • @ 2026-6-9 23:57:37
    #include <bits/stdc++.h>
    using namespace std;
    int main (){
    	int n;
    	cin>>n;
    	string s;
    	cin>>s;
    	int t1=s.find('(');//找到左括号位置
    	int t2=s.find(')');//找到右括号位置
    	string f;//f存循环节数字
    	for(int i=t1+1;i<t2;i++){
    		f=f+s[i];
    	} 
    	int dian=s.find('.');//找到小数点位置
    	int shuchang=t1-dian-1;//小数点后不循环部分长度
    	if(n<=shuchang){
    		cout<<s[n+dian];//目标位在不循环段,直接输出
    	}else {
    		int yu=(n-shuchang)%f.size();//算出除去不循环部分后的余数
    		if(yu==0)yu=f.size();//余数为0说明是一组末尾,换成循环节总长
    		cout<<f[yu-1];//输出循环节对应数字
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    5018
    时间
    ms
    内存
    MiB
    难度
    2
    标签
    递交数
    19
    已通过
    8
    上传者