一道wa了11次的模拟题

 

wudiii的后缀

Description

 

现在给你一个长度为n的字符串,去掉第i个字符后的字符串为si,

请对s1,s2,s3…sn进行排序,若两个字符串相同,则编号小的更小。

例如s1=s2,则s1更小。

Input

 

第一行一个整数n(1<=n<=500005)。

第二行一个由n个小写字母组成的字符串。

Output

 

输出一行n个整数k1、k2、…kn。表示sk1<sk2<…<skn。

Sample Input 1 

20
asdaaaabbdcccpppooaf

Sample Output 1

2 3 10 14 15 16 17 18 20 19 11 12 13 8 9 4 5 6 7 1

 

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
//	static InputReader sc=new InputReader(System.in);
	static PrintWriter out=new PrintWriter(System.out);
	static Scanner sc=new Scanner(System.in);
	static int n,m;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		n=sc.nextInt();
		String str=sc.next();
		char[] ch=new char[n+1];
		for(int i=0;i<n;i++) {
			ch[i]=str.charAt(i);
		}
			int[] node=new int[n+1];
			int left=0;
			int right=n-1;
			for(int i=0;i<n;i++) {
				if(ch[i]<ch[i+1]) {
					node[right]=i+1;
					right--;
				}else if(ch[i]==ch[i+1]) {
					int flag=1;
					int cnt=0;
					for(int j=i;j<n;j++) {
						if(ch[j]>ch[i]) {
							int key=j;
							while(cnt-->0) {
								node[right]=key--;
								i++;
								right--;
							}
							i--;
							flag=0;
							break;
						}else if(ch[j]<ch[i]) {
							while(cnt-->0) {
								node[left]=i+1;
								i++;
								left++;
							}
							i--;
							flag=0;
							break;
						}else
							cnt++;
					}
					if(flag==1) {
						while(cnt-->0) {
							node[left]=i+1;
							i++;
							left++;
						}
						break;
					}
				}else {
					node[left]=i+1;
					left++;
				}
			}
			for(int i=0;i<n;i++) {
				out.print(node[i]);
				if(i!=(n-1)) {
					out.print(" ");
				}
			}
		
		out.flush();
		out.close();
	}
}
//2 3 10 14 15 16 17 18 20 19 11 12 13 8 9 4 5 6 7 1

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值