标签:
2
1800081
180008945541
(空行)
package bnuzoj1261; import java.util.Scanner; public class Main { public static void run( String str ) { StringBuffer sb = new StringBuffer(); char[] chs = str.toCharArray(); sb.append( chs[ 0 ] ); for( int i = 1; i < str.length(); ) { if(sb.length() < 1){ sb.append( chs[i] ); i++; } else if( chs[ i ] != sb.charAt( sb.length()-1 ) ) { sb.append( chs[i] ); i++; } else { if( chs[i] == sb.charAt( sb.length()-1 )){ do{ i++; }while(i<chs.length && chs[i] ==sb.charAt( sb.length()-1 )); sb.delete(sb.length()-1,sb.length()); } } } System.out.println( sb.toString() ); } public static void main( String[] args ) { Scanner sc = new Scanner( System.in ); int T = sc.nextInt(); while( T-- > 0 ) { String str = sc.next(); run( str ); } } }
Ps:注意消除是左边优先.
[BNUZOJ1261][ACM][2016北理校赛]方块消除(栈,字符串)
标签:
原文地址:http://www.cnblogs.com/dick159/p/5570887.html