OnlineJudge | Online Judge is a programming contest judge | Runtime Evironment library
kandi X-RAY | OnlineJudge Summary
kandi X-RAY | OnlineJudge Summary
Online Judge is a programming contest judge built with Node.js (Express), AngularJS, PostgreSQL, and Docker.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of OnlineJudge
OnlineJudge Key Features
OnlineJudge Examples and Code Snippets
Community Discussions
Trending Discussions on OnlineJudge
QUESTION
I am new to programming. I am learning python. I am trying to solve a problem to develop my coding skill. Problem link: UVa 299 Train Swapping
I have written a code to solve the problem.
My code:
...ANSWER
Answered 2021-Feb-26 at 09:26Because x
only ranged from 0
to len(numbers) - 1
, counter
cannot be equal to len(numbers)
because even if everytime in the for x in range(len(numbers) - 1)
loop counter
increased by 1, the maximum it can get is still len(numbers) - 1
. So change your if
statement to
QUESTION
I'm solving a basic C problem on a site called UVa Online Judge, and I encounter an error which seems to related to compiler options.
...ANSWER
Answered 2021-Feb-11 at 18:55You're using C++ style comments in your code, i.e. //
.
Many C compilers will allow these types of comments as an extension, however strict ANSI C does not. You'll need to use C style comments /* ... */
.
So instead of this:
QUESTION
This is my list of input.
...ANSWER
Answered 2020-Dec-20 at 01:24You can override the definition of the input()
function to return values from your TestCase class.
I think I see what your input structure is all about. The 1
at the beginning defines how many sets of data are in the test case, and the remaining values are lists containing that many items. Since the first value is 1
, you only have one value in each secondary list. It is the first value from each list that you want to return for each call to input
after the first one.
The "output" you show is, I'm guessing, actually user input except for the last line. So when reading from your data set instead of taking user input, printing each value returned by your input()
function will verify what's going on and give you the output that you show.
Here's an extended version of your code that I think does what you want. I added a method to your TestCase
class to return the input data for that test case, one value at a time. I put the main body of your code in a main()
function that accepts a TestCase
object. In main()
, I overload input()
to point to that new method inside TestCase
to return input from the test case instead of getting it from the user. I didn't have to change the main body of your code at all. Here's what I did:
QUESTION
I am a beginner. I am practicing C++. I have written code that is not returning the answer from the function.
Here is my code:
...ANSWER
Answered 2020-Nov-06 at 09:21Here is the solution code. Notes:
- You have to use
if (a == 0 && b == 0 && c == 0)
instead ofif (a == b == c == 0)
. - You have to use lower case ex: right not Right.
QUESTION
I'm trying to solve a question from onlinejudge.org - The 3n + 1 Problem using Python.
in case the link doesn't load (that happens quite frequently), below is my summarized version of the question:
Consider the following algorithm:
- input n
- print n
- if n = 1 then STOP
- if n is odd then n <- 3n + 1
- else n <- n/2
- GOTO 2
Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
In the example above, the cycle length of 22 is 16.
For any two numbers i and j you are to determine the maximum cycle length over all numbers between and including both i and j.
Sample Input
...ANSWER
Answered 2020-Oct-09 at 08:04Given your code actually does generate the correct results for the given samples, it's a safe bet you're not handling the input data correctly. And, in fact, the problem statement states (my emphasis):
The input will consist of a series of pairs of integers
i
andj
, one pair of integers per line. All integers will be less than 10,000 and greater than 0.You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including
i
andj
.
Hence, your code that gets only one pair will not be sufficient. The reason it only processes one pair has to do with a misunderstanding that the code:
QUESTION
I was trying to solve UVA 11036. It requires defining function at runtime.
For Example: I have to take input (2*x + 7) % N
as a string and define a function at runtime like func = lambda x : (2*x + 7) % N
to work on it. Please help me to find out how to convert string to function at runtime.
ANSWER
Answered 2020-Aug-20 at 07:49It seems captivating riddle, so if you want to solve it in C++ have two way. The hard way is implementing a small math parser using some algorithms like Shunting-yard algorithm. Or instead of, if you are familiar with library linking in C++, it is better to use a mathematical expression parser libraries. There are many libraries on Internet. Here, I suggest one of them as below.
mathematical expression library I personalty have tested it and obviously is fast. you can clone source code in GitHub
Anyway, you can not solve this case with lambda functions because, the input is a mathematical expression you should parse and calculate it runtime.
if you use python see this post.
QUESTION
I am trying to solve uva's question 10534. The question is straight forward i.e
- Store LIS at each index i in array
L1[]
. - Reverse the input array
nums[]
. - Store LIS of this reverse array
nums[]
inL2[]
- Reverse
L2[]
. - Now
L2[]
represents LIS at index i from right instead of left.
I pass the sample test cases but every time I submit I get Runtime error. Can anybody explain why is that? and where do I need to change my code.
...ANSWER
Answered 2020-May-16 at 12:36Not sure is your input method ok for uva solution...
Try with this:
QUESTION
Now I am trying to solve the UVa problem 843: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=784
And here is the c++ code I tried for it.
...ANSWER
Answered 2020-May-05 at 19:00Turning on -fsanitize=undefined
, I got a warning in hasConflict
about an index out of bounds.
Indeed, it seems that hasConflict
is sometimes passed strings containing *
, in which case used[*iter - 'a']
is outside the bounds of bool used[26]
.
Not sure if that's the bug causing your failure, but it's certainly a bug.
QUESTION
I have this line in my code (ll is long long int):
...ANSWER
Answered 2017-Jan-28 at 12:00First, there is no floating-point arithmetic going on here: everything is done in integers (specifically, long long int
s).
This means that when y
is between 1000000
and 1999999
, inclusive, the result of the division y / 1000000
is going to be 1
. Hence, subtracting 1
from it would lead to zero denominator, and a division by zero exception.
Your second expression will produce the same result only when y
is equal to 1000000
, but the program is going to crash with the same exception.
The trick to solving problems of this kind is keeping numerator and denominator separate, and performing your math entirely in integers, i.e. without floating point numbers. Constructing a simple class for representing rational numbers should help simplifying your code.
QUESTION
My code compiled(g++) without errors and ran without errors on my system(Macos) for sample input from the website, but is showing a Runtime Error in the online judge. Please help, I'm a new programmer. This is the problem statement.
My program returns correct results for the test input data.
They haven't given the exact reason for the runtime error. The website has this information about runtime error:
Runtime Error (RE): Your program failed during the execution (segmentation fault, floating point exception...). The exact cause is not reported to the user to avoid hacking. Be sure that your program returns a 0 code to the shell.
...ANSWER
Answered 2020-Mar-19 at 11:03Solved the problem :
Program run without any errors with runtime : 0.330s
The runtime error was solved when I replaced the stoi() function with input formatting.
Finally there was an output error because I was flipping k and j to prevent undefined behavior when j < k, which I solved by formatting the output accordingly.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
Install OnlineJudge
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page