wudiii的后缀
Description
现在给你一个长度为n的字符串,去掉第i个字符后的字符串为si,
请对s1,s2,s3…sn进行排序,若两个字符串相同,则编号小的更小。
例如s1=s2,则s1更小。
Input
第一行一个整数n(1<=n<=)。
第二行一个由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
2025年一道wa了11次的模拟题
一道wa了11次的模拟题wudiii 的后缀 Description 现在给你一个长度为 n 的字符串 去掉第 i 个字符后的字符串为 si 请对 s1 s2 s3 sn 进行排序 若两个字符串相同 则编号小的更小 例如 s1 s2 则 s1 更小 Input 第一行一个整数 n 1 lt
大家好,我是讯享网,很高兴认识大家。
99件事之二
上一篇
2025-01-05 18:15
C开发微信门户及应用(28)--微信“摇一摇·周边”功能的使用和接口的实现
下一篇
2025-03-06 10:49

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/34060.html