Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:第一次弄这个练习In Reply To:第一次弄这个练习 Posted by:dreamwf at 2009-04-14 21:14:23 import java.util.Scanner; public class Main { private int n; private String[] result; private String[] input;; public String[] input() { Scanner in=new Scanner(System.in); n=Integer.parseInt(in.nextLine()); input=new String[n]; char[] single=new char[7]; for(int i=0;i<n;i++){ int au=0; String temp=in.nextLine(); for(int j=0;j<temp.length();j++){ int asc=temp.charAt(j); if(asc==81||asc==113){continue;} if(asc>=48&&asc<=57||asc>=65&&asc<90||asc>=97&&asc<122){ if(asc>=97){ asc=asc-32; System.out.println(asc); char a=this.mapping(asc); single[au++]=(char) a; }else{ char a=this.mapping(asc); single[au++]=(char) a; } }else{ continue; } } input[i]=new String(single); } return input; } public char mapping(int asc){ char num='2'; char cha='A'-1; char temp=(char) asc; for(int i=1;i<=25;i++){ cha++; if(cha=='Q'){ i--; continue; } if(temp==cha){ temp=num; return temp; } if(i%3==0)num++; } return temp; } public String[] sort(String[] input){ for(int i=0;i<input.length;i++){ for(int j=i;j<input.length;j++){ String t=null; if(Integer.parseInt(input[i])>Integer.parseInt(input[j])){ t=input[i]; input[i]=input[j]; input[j]=t; } } } return input; } public String[] classify(String[] aaa){ String[] result =new String[n]; int numbers=1; for(int i=0;i<aaa.length-1;i++){ if(aaa[i].equals(aaa[i+1])){ numbers++; //result[i]=new String(aaa[i]+" "+numbers); }else{ if(numbers!=1){ result[i]=new String(aaa[i]+" "+numbers); numbers=1; } } } return result; } public boolean isallnull(String[] bb ){ for(int i=0;i<bb.length;i++){ if(bb[i]!=null)return false; } return true; } public static void main(String[] args){ Main t=new Main(); String[] input=t.input(); input=t.sort(input); String[] result =t.classify(input); if(t.isallnull(result)){ System.out.println("No duplicates"); }else{ for(int i=0;i<result.length;i++) { if(result[i]!=null){ String str1=new String(result[i].substring(0, 3)); String str2=new String(result[i].substring(3)); result[i]=new String(str1+"-"+str2); System.out.println(result[i]); } } } } } 这个是我写的代码。才学编程没半年呢。程序写的很垃圾。高手指点下 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator