广东新生赛m

在这里插入图片描述

感觉还行吧比较扎实的一题也算比较简单
就是周期性找个规律
但是是超大的数
所以用到了同余
字符串实现
我是又构造了辅助的字符数组好找下标
我的代码有点点浪费时间因为长度知道了我又给算了一遍
影响不大

#include<bits/stdc++.h>
using namespace std;
char s[35],temp[35],m[10000];
int main()
{
	int n;
	scanf("%d%s",&n,m);
	scanf("%s",s);
	int len=strlen(s);
	int t=2*len;
	int lenth=strlen(m);
	int ans=0,cnt=0;
	for(int i=0;i<lenth;i++)
		ans=(ans*10+m[i]-'0')%t;
	for(int i=0;i<len;i++)
		temp[cnt++]=s[i];
	for(int j=len-1;j>=0;j--)
		temp[cnt++]=s[j];
	if(!ans)
		printf("%c\n",temp[cnt-1]);
	else
		printf("%c\n",temp[ans-1]);
	return 0;
}
发布了54 篇原创文章 · 获赞 4 · 访问量 884

猜你喜欢

转载自blog.csdn.net/weixin_45460987/article/details/103442197
今日推荐