Re: [問題] 用Java寫ACM題目,輸入的問題
※ 引述《StarView (星演)》之銘言:
: 最近在練習用Java寫程式,就找了一題簡單的ACM第476題來解解看.
: languajes. Note that java::io use is restricted; this implies that some
: features (for example, to create a DataInputStream variable with System.in as
: argument, in order to use readLine to read strings from the standard input) are
: not available.
: 所以我的code會compile error是因為用System.in及readLine的原故,
: 我對Java還不是很熟...
: 想請教一下各位高手我該怎麼修改輸入的寫法? 才能通過ACM java compiler的考驗,
: 另外想請教ACM的Java compiler:gcj也同步支援到jdk5.0嗎?
: 感謝回答..
        我沒看你程式...but講一下之前的經驗
        只支援到JDK 1.2左右吧...總之很糟糕.....
        當初只寫完100~103就沒勇氣再試下去了(汗)
        至於輸入的寫法...請善用System.in.read()
        網路上的範例碼如下
    static String ReadLn (int maxLg)  // utility function to read from stdin
    {
        byte lin[] = new byte [maxLg];
        int lg = 0, car = -1;
        String line = "";
        try
        {
            while (lg < maxLg)
            {
                car = System.in.read();
                if ((car < 0) || (car == '\n')) break;
                lin [lg++] += car;
            }
        }
        catch (IOException e)
        {
            return (null);
        }
        if ((car < 0) && (lg == 0)) return (null);  // eof
        return (new String (lin, 0, lg));
    }
--
    String temp="relax";                     |  Life just like programing
    while(buringlife)  String.forgot(temp);  |      to be  right or wrong
    while(sleeping)    brain.setMemoryOut(); |        need   not  to  say
    stack.push(life.running);                |         the complier  will
    stack.push(scouting.buck());             |           answer your life
--
※ 發信站: 批踢踢實業坊(ptt.cc) 
◆ From: 140.138.240.58
討論串 (同標題文章)
java 近期熱門文章
PTT數位生活區 即時熱門文章