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 |
sample只是sample,并不是测试数据.你是pku的,还不知道 ?In Reply To:为什么 我的程序用SAMPLE的输入没错,但是一提交后,就出现WA???? Posted by:small_dao at 2007-03-01 10:03:57 > import java.util.*; > import java.io.*; > > public class Main > { > private ArrayList<String> numbers; > private BufferedReader stdin; > > public Main(){ > numbers = new ArrayList<String>(); > stdin = new BufferedReader( new InputStreamReader(System.in)); > > } > > public char map(char ch){ > > if(ch>='A'&&ch<='C') return '2'; > else if(ch>='D'&&ch<='F') return '3'; > else if(ch>='G'&&ch<='I') return '4'; > else if(ch>='J'&&ch<='L') return '5'; > else if(ch>='M'&&ch<='O') return '6'; > else if(ch>='P'&&ch<='S'&&ch!='Q') return '7'; > else if(ch>='T'&&ch<='V') return '8'; > else if(ch>='W'&&ch<='Y') return '9'; > > return ch; > } > > public void numbers_in(){ > > try{ > String str = stdin.readLine(); > > int size = Integer.valueOf(str).intValue(); > > for(int k=0; k<size; k++){ > str = stdin.readLine(); > StringBuffer strBuf = new StringBuffer(); > > int pos = 0; > for(int i=0; i<str.length(); i++) > { > char ch = str.charAt(i); > > if(pos==3){ > strBuf.append('-'); > pos++; > } > > if((ch = this.map(ch))!= '-'){ > strBuf.append(ch); > pos++; > } > } > > numbers.add(new String(strBuf)); > } > }catch(Exception e){ > > } > > Collections.sort(numbers); > > } > > public void numbers_out(){ > > int count = 1; > boolean duplicated = false; > > for(int i=0; i<numbers.size()-1;i++) > { > if(numbers.get(i).compareTo(numbers.get(i+1)) == 0){ > count++; > }else{ > if(count>1){ > System.out.println(numbers.get(i) + " " + count ); > count = 1; > duplicated = true; > } > } > > } > > if(!duplicated){ > System.out.println("No duplicates."); > } > > } > > public static void main(String[] args){ > > Main t = new Main(); > t.numbers_in(); > //System.out.println(); > t.numbers_out(); > } > > > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator