题意:
需要构造一个由从1到n的数字组成的序列,并且给出一个字符串,由'>',和 ‘<’组成,第i个字符表示第i个数字和第i+1个数字的大小关系,字符串长度是n-1, 所构成的序列需要满足大小关系。输出两个序列,第一个序列要使最长上升子序列的长度最短,第二个序列要让长度最长。
思路:
让最长上升子序列长度最长,就是让序列整体呈现出上升的趋势,所以把序列初始化为从1到n的序列,然后再根据大小关系用reverse函数进行调整。
#pragma warning(disable:4996)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
char s[200005];
int ans[200005];
int main()
{
int t, i, j, n;
scanf("%d", &t);
while (t--) {
scanf("%d%s", &n, s+1);
for (i = 1; i <= n; i++)
ans[i] = n - i + 1;
for (i = 1; i < n;)
{
j = i;
while (s[j] == '<')
j++;
reverse(ans + i, ans + j + 1);
i = j + 1;
}
for (i = 1; i <= n; i++) {
printf("%d ", ans[i]);
}
printf("\n");
for (i = 1; i <= n; i++)
ans[i] = i;
for (i = 1; i < n;)
{
j = i;
while (s[j] == '>')
j++;
reverse(ans + i, ans + j + 1);
i = j + 1;
}
for (i = 1; i <= n; i++) {
printf("%d ", ans[i]);
}
printf("\n");
}
return 0;
}