how to use octave on hackerrank website?

hi there,
now I am trying to use octave to do the hackerrank test, but everytime I click on the 'Run code' button, it always says that 'no response on stdout', here is the code and note:
# Enter your code here. Read input from STDIN. Print output to STDOUT
a = stdin;
pivot = a(1);
equal = pivot;
left = a(a<pivot);
right = a(a>pivot);
stdout = [left equal right];
Does anyone knows this? Many thanks!

7 个评论

Weiqian - perhaps try usig printf instead. Also, is
stdout = [left equal right];
the correct syntax for using stdout?
Hi Hayes, thanks for replying, I am not sure whether my syntax is correct, I just did what is correct form in matlab, and I also tried using printf: printf(stdout), but it still results in the same error...
Have you checked the Octave doc?
You could try just
printf('<format_string>',yourVariables)
which should (?) print the output to stdout.
hi, thanks for answering, I have solved this problem by the following code, and the result is the same as the expect output: 3 2 4 5 7, but my output is 3 2 4 5 7, expected output is 3 2 4 5 7, so my result is error- -|| Does anyone know why? My code is as follows:
n = scanf('%d',1);
a = scanf("%d",[1,n]);
pivot = a(1);
equal = pivot; left = []; right = []; b = [];
for i = 1:length(a)-1
if a(i+1)<equal
left = [left,a(i+1)];
elseif a(i+1)>equal
right = [right,a(i+1)];
end;
end;
b = [left,equal,right];
disp(b);
Weiqian - if you need exactly one space between each character then perhaps try something like
printf('%d', b(1));
for k = 2:length(b)
printf(' %d')
end
instead of disp.
hi Geoff, thanks for your reply, I used 'fprintf('%d ',b);' and it works,thanks.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Octave 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by