This problem is very pit dad, a little attention is not PE is RA or tle.
First, test instructions:
The description of the problem is not very clear, mainly through the topic of the example of their own summary, (this is the key, not to find a good law will always tle):
Rule: The following string is compared with the previous string, if the number of the same characters is greater than the number of spaces, then the number of spaces plus 1, if the number of the previous number of the same character is less than the amount of space, then the number of spaces to the same number of characters.
Java implementation of the Code on the web basically did not find, no way, before POJ on a total of 4 predecessors with the Java AC, can only do their own hands,
Start my direct violence compared directly to print, finally the RA solved, but unfortunately tle,
This problem with c,c++ all to 500ms+, with Java or a bit difficult,
I optimized the half-day, racking up the brains, and finally AC:
The following code is shared with lazy people:
import Java.io.bufferedreader;import java.io.ioexception;import java.io.InputStreamReader; Public classMain { Public Staticstringbuffer[]b=Newstringbuffer[ One]; Public Static intBlank; Public Static voidMain (String[]args) throws ioexception{BufferedReaderinch=NewBufferedReader (NewInputStreamReader (System.inch)); String Str="" ; String Next; Blank=0; Init (); while(Next =inch. ReadLine ())! =NULL) {Write (str,next); STR=Next; } } Public Static voidWrite (String str,string next) {intsame =GSN (Str,next); if(same>blank) {Blank++; }Else if(same<blank) {Blank=same; } System. out. println (b[blank]+next); } Public Static intGSN (String s1,string s2) {//Getsamenumber intLen = S1.length () >s2.length ()?s2.length (): S1.length (); inti; for(i=0; i<len;i++){ if(S1.charat (i)! =S2.charat (i)) { Break; } } returni; } Public Static voidinit () {StringBuffer sb; for(intI=0;i< One; i++) {SB=NewStringBuffer (""); for(intj=0; j<i;j++) {sb.append (" "); } B[i]=SB; } }}
To add, the print of that space is a waste of time, seemingly no way to print a few spaces in Java, if each time with a for implementation, then definitely tle, because the string length is not greater than 10, so I used the table, this can save a lot of time.
POJ 1750 Java