Pages

1/19/2014

UVA 483 Word Scramble solution

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

class Main {

/**
* @param args
* @throws IOException
*/
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
boolean flag = false;
String m = null;
StringBuffer res = new StringBuffer("");
while ((m= br.readLine())!=null){
String[] sa = m.split(" ");

if(flag) res.append("\n");
                         flag = true;
StringBuffer b = new StringBuffer("");
                        boolean bt= false;
for (int i = 0 ; i < sa.length; i++) {

StringBuffer t = new StringBuffer(sa[i]).reverse();
                                if (bt) b.append(" ");
b.append(t);
                                bt = true;
}
res.append(b);

}
System.out.println(res);
}
}

No comments :

Post a Comment