⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2241886_wa.cc

📁 北大大牛代码 1240道题的原代码 超级权威
💻 CC
字号:
# include <stdio.h>
# include <string.h>
# include <algorithm>

int len, p;
char com[2], w[10002];

struct node
{
	int p;
	char tmp;
}Str[10002];

void work()
{
	int i, tt;
	int next[10001], num[27], sum[27];
	
	memset(num,0,sizeof(num));
	for(i = 0; i < len; i++)
		num[w[i]-'a']++;
	sum[0] = 0;
	for(i = 1; i < 27; i++)
		sum[i] = sum[i-1]+num[i-1];
	for(i = 0; i < len; i++)
	{
		next[sum[w[i]-'a']++] = i;
	}
	for(i = 0; i < len; i++)
		if(next[i]==p-1)
		{
			tt = i;break;
		}
	for(i = 0; i < len; i++)
	{
			printf("%c",w[next[tt]]);
			tt = next[tt];
	}
	printf("\n");
}

bool cmp(struct node a,struct node b)
{
	if(a.tmp!=b.tmp)
		return a.tmp<b.tmp;
	else
		return a.p < b.p;
}

void input()
{
	int i, t;

	scanf("%s",com);
	if(com[0]=='A')
	{
		scanf("%d%s",&len,w);
		for(i = 0; i < len; i++)
			Str[i].p = i,Str[i].tmp = w[i];
		std::sort(Str,Str+len,cmp);
		for(i = 0; i < len; i++)
		{
			t = Str[i].p - 1;
			if(t==-1)
				t = len-1;
			printf("%c",w[t]);
			if(Str[i].p==1)
				p = i;
		}
		printf("\n%d\n",p+1);
	}
	else
	{   
		scanf("%d%s%d",&len,w,&p);
		work();
	}
}

int main()
{
	input();
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -