Please review my code, i’m getting wrong answer but on my machine i ran 1000s of testcases easily.
IO.open();
InputStream is = System.in;
int testCases = IO.readInt();
IO.read();
char[] buf = new char[50];
int index=0, lastSpace=-1, tmp=0, count=0;
while(testCases>0) {
index=-1; lastSpace=-1;
do {
index++;
buf[index] = Character.toLowerCase((char)IO.read());
if(buf[index]==' ') {
if(lastSpace == -1) {
buf[0]=Character.toUpperCase(buf[0]);
buf[1]='.';
buf[2]=' ';
index=2;
lastSpace=2;
} else {
buf[lastSpace+1]=Character.toUpperCase(buf[lastSpace+1]);
buf[lastSpace+2]='.';
buf[lastSpace+3]=' ';
index=lastSpace+3;
lastSpace+=3;
}
}
} while(buf[index] != '\n');
if(lastSpace==-1) {
buf[0]=Character.toUpperCase(buf[0]);
buf[1]='.';
index=3;
} else {
buf[lastSpace+1]=Character.toUpperCase(buf[lastSpace+1]);
}
IO.println(new String(buf,0,index-1));
testCases--;
}
IO.close();