Hi,
I'm new at UVA Online Judge system and i'm having a few troubles. I'm programing in JAVA and my program consists in an algorythim similar to this:
"
Code: Select all
public static void main(String[] args)
{
while (true)
{
// something to read the number and stock it in the variable "N"
if(N == 0)break;
System.out.println(solve(N));
}
}
static long solve(int N)
{
if(N == 1)return 1;
if(N == 2)return 2;
if(N == 3)return 3;
long[] fib = new long[N];
fib[0] = 1; fib[1] = 2; fib[2] = 3;
for(short i = 3; i < N; i++) fib[i] = fib[i-1] + fib[i-2];
return fib[N-1];
}
}
"
>>>My first problem was that i didn't really understand how do you do to read information from the input in this kind o problems. So I've copied the method ReadLn() from the sample solution of problem 100. Then my program was like this:
Code: Select all
import java.io.*;
import java.util.*;
class teste2
{
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));
}
public static void main(String args[])
{
while (true)
{
String input = ReadLn (255);
StringTokenizer st = new StringTokenizer(input);
int N = Integer.parseInt(st.nextToken());
if(N == 0)break;
System.out.println(solve(N));
}
}
static long solve(int N)
{
if(N == 1)return 1;
if(N == 2)return 2;
if(N == 3)return 3;
int[] fib = new int[N];
fib[0] = 1; fib[1] = 2; fib[2] = 3;
for(short i = 3; i < N; i++) fib[i] = fib[i-1] + fib[i-2];
return fib[N-1];
}
}
>>>Then I've received the following message:
Dear gaucho.andre:
The compiler couldn't compile your ANSI C/C++ or GNU Pascal/Java program.
[Notes: - Select C, C++, JAVA or PASCAL in the @JUDGE_ID field, to ensure that
I'll use the proper compiler. Place a 'program...' sentence in Pascal.
Note that entry point in Java is a 'main' function in a 'Main' class.
- Do not use more than 1024 characters per line, or 40,000 bytes per
program, if you are submitting your programs by E-Mail.
- Do not use '//' comments except in C++ programs [And Note that this
is not Borland C or Turbo Pascal!].
- Some mail tools reformat your text or the standard mail headers.
I compiled the lines I resent you in the "Program Received" message.
(if your mail system adds extra lines to your letter, please include
a "@end_of_source_code" string after the last source code line).
Here are the compiler error messages:
/tmp/cceioHadmain.o: In function `main':
/tmp/ccY7Ehzvmain.i(.text+0x12): undefined reference to `_CL_4Main'
collect2: ld returned 1 exit status
>>>Could you please help me and tell me what's wrong about this code for solving the problem? And how do i read thing from the input since i can't use the Scanner clas. I would thanks if you answer to my e-mail (
gaucho.andre@gmail.com).
Thanks,
gaucho.andre