今天美菜网的笔试第二题,大佬们有什么样的思路吗
我只AC了33%,也就是样例我给完成了
我的做法是
package com.study.Java; import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); String s=sc.nextLine(); System.out.print(DestoryText(s)); } private static String DestoryText(String s) { // TODO Auto-generated method stub char[] c=s.toCharArray(); StringBuffer sb=new StringBuffer(s); int a=0,b=0; for( int i=0;i<c.length;i++) { if(c[i]=='$') a=i; if(c[i]=='#') b=i; } if(a==0&&b==0)return sb.toString(); String sub1=sb.substring(0, a); if(b==0) { String sub2=sb.substring(a+1, c.length); return sub2+sub1; } String sub2=sb.substring(a+1, b); String sub3=sb.substring(b+1, c.length); /**System.out.println(sub1); System.out.println(sub2); System.out.println(sub3);**/ return sub2+sub1+sub3; } }