作者TonyQ (骨头)
看板java
标题Re: [问题] 用Java写ACM题目,输入的问题
时间Sat Feb 25 15:29:34 2006
※ 引述《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