这是百度的一道算法题,很简单,当时却没做出来,太紧张了。
1 package 单词逆序; 2 3 import java.util.Scanner; 4 5 public class Nixu { 6 7 public static void main(String[] args) { 8 // TODO Auto-generated method stub 9 10 String string = new String(); 11 Scanner in = new Scanner(System.in); 12 13 string = in.nextLine(); 14 15 String []str = string.split(" "); 16 String danci = new String(); 17 String s = new String(); 18 for(int i=str.length-1;i>=0;i--) 19 { 20 char []x = str[i].toCharArray(); 21 int flag=0; 22 for(int j=0;j<x.length;j++) 23 { 24 if(x[j]<'A' || x[j]>'z') 25 { 26 flag=1; 27 } 28 } 29 if(flag==0) 30 danci = danci +str[i]+" "; 31 } 32 33 for(int i=0;i<str.length;i++) 34 { 35 char []x = str[i].toCharArray(); 36 int flag=0; 37 for(int j=0;j<x.length;j++) 38 { 39 if(x[j]<'A' || x[j]>'z') 40 { 41 flag=1; 42 } 43 } 44 if(flag==1) 45 s =s +str[i]+" "; 46 } 47 48 49 System.out.println(danci+s); 50 51 } 52 53 }