題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1302
import java.util.*; import java.lang.*; import java.lang.StringBuilder; public class Main{ public static void main(String[] args) { Scanner console = new Scanner(System.in); int times = console.nextInt(); console.nextLine(); while(times--!=0){ String input = console.nextLine(); int s1Index,s2Index,s3Index,s4Index,s5Index; for(s1Index=0 ; input.charAt(s1Index)!='<';s1Index++); s2Index = s1Index+1; s1Index--; StringBuilder s2 = new StringBuilder(); for(s3Index=s2Index ; input.charAt(s3Index)!='>' ; s3Index++){ s2 = s2.append(input.charAt(s3Index)); } s3Index++; StringBuilder s3 = new StringBuilder(); for(s4Index=s3Index; input.charAt(s4Index)!='<';s4Index++){ s3 = s3.append(input.charAt(s4Index)); } s4Index++; StringBuilder s4 = new StringBuilder(); for(s5Index=s4Index; input.charAt(s5Index)!='>';s5Index++){ s4 = s4.append(input.charAt(s5Index)); } s5Index++; StringBuilder s5 = new StringBuilder(); for(int Index=s5Index; Index < input.length();Index++){ s5 = s5.append(input.charAt(Index)); } String l2 = console.nextLine(); String c1Last = input.substring(s1Index+1,input.length()); String c1Default = s2.toString()+s3.toString()+s4.toString()+s5.toString(); String c1 = input.replace(c1Last, c1Default); String c1Decoded = s4.toString()+s3.toString()+s2.toString()+s5.toString(); System.out.println(c1); String c2 = l2.replace("...",c1Decoded); System.out.println(c2); } } }
沒有留言:
張貼留言