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 1196. History Exam

wa1
Posted by Iliya (Java) 26 Oct 2008 05:10
What's wrong in my program?(It passed all my tests)
import java.io.*;

public class Task1196 {
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(
                new InputStreamReader(
                        System.in
                )
        );
        in.nextToken();
        int n = (int) in.nval;
        long prep[] = new long[n];
        for(int i=0;i<n;i++){
            in.nextToken();
            prep[i]=(long)in.nval;
        }
        long ans = 0;
        in.nextToken();
        long m =(long)in.nval;
        for(int i=0;i<m;i++){
            in.nextToken();
            if(binSearch(prep,(long)in.nval)){
                ans++;
            }
        }
        System.out.print(ans);
    }
    public static boolean binSearch(long[] prep,long date){
        int down=0;
        int up = prep.length-1;
        int m;
        while(true){
            m= (up+down)/2;
            if(prep[m]>date){
                up=m-1;
            }else if(prep[m]<date){
                down=m+1;
            }else{
                return true;
            }
            if(down>up){
                return false;
            }
        }
    }
}
Re: wa1
Posted by [SPbSU ITMO] WiNGeR 26 Oct 2008 05:14
There are some problems with Java now..
Every program in Java gets wa1 (

Edited by author 26.10.2008 05:20
Re: wa1
Posted by Ilya (Vologda SPU) 27 Oct 2009 21:49
Really? It's sux >_<

I get known that there is another scanner required:
Scanner scanner = new Scanner(System.in, "ISO-8859-1");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-1"));
PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out, "ISO-8859-1"));

It's written here:
http://acm.timus.ru/help.aspx?topic=java (look at the bottom of the page)

I just like to know WHERE and HOW I should paste this new scanner into my program in order to it behave!


Edited by author 29.10.2009 00:44
Re: wa1 LK at the OUTPUT explain
Posted by yangdong 21 Oct 2010 13:31
"Output the number of dates in the student's that are also contained in Professor's list."
you needn't count the time it appears ...
count the amount of appear numbers in list 2 is just OK...
Re: wa1
Posted by [PNTU]Sergiy D 22 Apr 2011 21:59
On C++ the same problem now.
Re: wa1
Posted by Nafania 21 Oct 2011 15:37
yangdong is right.

Hint: use list or set for first dates and you will be happy. ^_^

P.S.: Sorry for my English :)

Edited by author 21.10.2011 15:39