|
|
back to boardWA6 Why I've got WA test 6? import java.io.*; import java.util.*; public class Trolley{ public static void main(String args[])throws Exception{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int a=0,b=0; while(in.ready()){ StringTokenizer st = new StringTokenizer(in.readLine()); while(st.hasMoreTokens()){ String s = st.nextToken("|.,/][';:\"{}!@#$%^&*()_+=- "); if(s.equals("tram"))a++; else if(s.equals("trolleybus"))b++; } } if(a>b)System.out.println("Tram driver"); else if(b>a)System.out.println("Trolleybus driver"); else System.out.println("Bus driver"); } } What is wrong? Re: WA6 Posted by LLIRIK 29 May 2009 23:06 try test trolleybu out Bus driver P.S. My prog works bad on this test Edited by author 30.05.2009 00:32 Edited by author 30.05.2009 00:38 Re: WA6 i have the same problem on java Re: WA6 I have AC with string nextToken("`~!@#$%^&*()-_=+\\|[{]};:'\",<.>/?№ "); Test 6 contains '№' symbol. Re: WA6 I rewrited Scanner for that problem.It's very simple :) class Scanner{
StreamTokenizer in;
Scanner(InputStream stream){ in = new StreamTokenizer(new InputStreamReader(stream)); in.resetSyntax(); in.whitespaceChars(0, 127); in.ordinaryChars('a','z');//cлово обязано начинаться с символа ordinary. А далее может быть что угодно из wordChar. in.wordChars('a','z'); }
void asserT(boolean e){ if (!e){ throw new Error(); } }
String nextWord(){ try{ in.nextToken(); if (in.ttype == in.TT_EOF){ return null; } asserT(in.ttype == in.TT_WORD); return in.sval; }catch (IOException e){ throw new Error(); } } } And then called "String word = in.nextWord();" Edited by author 28.01.2010 13:08 |
|
|