ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1612. Tram Forum

WA6
Posted by Nurlan Muldashev 13 Oct 2008 13:44
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
Posted by alexey saybel 28 Jan 2010 10:41
i have the same problem on java
Re: WA6
Posted by alexey saybel 28 Jan 2010 11:06
I have AC with string nextToken("`~!@#$%^&*()-_=+\\|[{]};:'\",<.>/?№ "); Test 6 contains '№' symbol.
Re: WA6
Posted by unlucky [Vologda SPU] 28 Jan 2010 13:07
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