为什么在让原字符串做首字母,排序字符串做尾字母不可以求解呢?
  • 板块P1124 文件压缩
  • 楼主Snial
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/3/17 02:07
  • 上次更新2023/10/28 06:25:15
查看原帖
为什么在让原字符串做首字母,排序字符串做尾字母不可以求解呢?
576902
Snial楼主2022/3/17 02:07
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
	int n, m,num;
	cin >> n;
	char str[100006], str1[100006],str2[100006],str3[100006];
	//str--原数组,str2--排序数组,str1--结果数组 
	char ch, temp;
	cin >> str;
	cin >> m;
	int i, j, s, k;
	strcpy(str2, str);
	strcpy(str3, str);
	//排序
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (str2[i] < str2[j])
			{
				temp = str2[i];
				str2[i] = str2[j];
				str2[j] = temp;
			}
		}
	}
	num=0;
	str1[0]=str[0];
	for (i = 1; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (str2[num] == str[j])
			{
				str1[i] = str[j];
				num = j;
				str[j]='0';
				break;
			}
		}
	}
    /*	for(i=0;i<n;i++)
	{
		cout<<str1[i];
	}*/
//	cout<<endl;
	for (i=0,j= m-1; i < n; i++,j++)
	{
		if(j==n)
		{
			j=0;
		}
		cout <<str1[j];
	}
	return 0;
}
2022/3/17 02:07
加载中...