Diễn Đàn MathScopeDiễn Đàn MathScope
  Diễn Đàn MathScope
Ghi Danh Hỏi/Ðáp Thành Viên Social Groups Lịch Ðánh Dấu Ðã Ðọc

Go Back   Diễn Đàn MathScope > Tin Học > Phần Mềm + Mã Nguồn

News & Announcements

Ngoài một số quy định đã được nêu trong phần Quy định của Ghi Danh , mọi người tranh thủ bỏ ra 5 phút để đọc thêm một số Quy định sau để khỏi bị treo nick ở MathScope nhé !

* Nội quy MathScope.Org

* Một số quy định chung !

* Quy định về việc viết bài trong diễn đàn MathScope

* Nếu bạn muốn gia nhập đội ngũ BQT thì vui lòng tham gia tại đây

* Những câu hỏi thường gặp

* Về việc viết bài trong Box Đại học và Sau đại học


Trả lời Gởi Ðề Tài Mới
 
Ðiều Chỉnh Xếp Bài
Old 24-01-2013, 05:38 PM   #1
hoang_kkk
+Thành Viên+
 
hoang_kkk's Avatar
 
Tham gia ngày: Jul 2012
Bài gởi: 103
Thanks: 259
Thanked 68 Times in 32 Posts
Lỗi tràn stack trong Free Pascal

Anh chị em nào pro về tin học có thể chỉ giúp em vì sao code của chương trình này lại bị tràn stack không ạ :

Code:
program going_one_going_twice_gone;
const   max=1001;
        fi='cow.inp';
        fo='cow.out';
type    m1=array[0..max] of longint;
       
var     a:m1;
        m,n : integer;
        f:text;
        ok:m2;
        max_cost,tong_max:longint;
procedure input;
var       i : integer;
begin
  assign(f,fi); reset(f); readln(f,n,m);
  for i:=1 to m do
   readln(f,a[i]);
  close(f);
end;
procedure sort(l,r : integer);
var       i,j,tg,x : integer;
begin
  x:=a[(l+r) div 2];
  i:=l;
  j:=r;
  repeat
    while (a[i]<x) do inc(i);
    while (a[j]>x) do dec(j);
    if i<=j then
    begin
      tg:=a[i]; a[i]:=a[j]; a[j]:=tg;
      inc(i);
      dec(j);
    end;
    until i>j;
  if l<j then sort(l,j);
  if i<r then sort(i,r);
end;
procedure xuly_chinh;
var       i,j,k:integer;
begin
  assign(f,fo); rewrite(f);
  sort(1,m);
  fillchar(ok,sizeof(ok),false);
  i:=m+2;
  a[m+1]:=0;
  a[m+2]:=0;
  a[0]:=0;
  max_cost:=0;
  tong_max:=0;
  while a[i]+a[i-1]<=a[i]*m  do
  begin
    dec(i,2);
  max_cost:=a[i];
  tong_max:=max_cost*(m-i+1);
  end;
  write(f,max_cost,' ',tong_max);
  close(f);
end;
begin
  input;
  xuly_chinh;
end.
Nó bị lỗi tràn ở dòng
Code:
dec(i,2)

[RIGHT][I][B]Nguồn: MathScope.ORG[/B][/I][/RIGHT]
 
hoang_kkk is offline   Trả Lời Với Trích Dẫn
Old 24-01-2013, 10:20 PM   #2
franciscokison
+Thành Viên+
 
franciscokison's Avatar
 
Tham gia ngày: May 2009
Đến từ: Hanoi University of Science and Technology
Bài gởi: 652
Thanks: 120
Thanked 249 Times in 181 Posts
Gửi tin nhắn qua MSM tới franciscokison Gửi tin nhắn qua Yahoo chát tới franciscokison
Trích:
Nguyên văn bởi hoang_kkk View Post
Anh chị em nào pro về tin học có thể chỉ giúp em vì sao code của chương trình này lại bị tràn stack không ạ :

Code:
program going_one_going_twice_gone;
const   max=1001;
        fi='cow.inp';
        fo='cow.out';
type    m1=array[0..max] of longint;
       
var     a:m1;
        m,n : integer;
        f:text;
        ok:m2;
        max_cost,tong_max:longint;
procedure input;
var       i : integer;
begin
  assign(f,fi); reset(f); readln(f,n,m);
  for i:=1 to m do
   readln(f,a[i]);
  close(f);
end;
procedure sort(l,r : integer);
var       i,j,tg,x : integer;
begin
  x:=a[(l+r) div 2];
  i:=l;
  j:=r;
  repeat
    while (a[i]<x) do inc(i);
    while (a[j]>x) do dec(j);
    if i<=j then
    begin
      tg:=a[i]; a[i]:=a[j]; a[j]:=tg;
      inc(i);
      dec(j);
    end;
    until i>j;
  if l<j then sort(l,j);
  if i<r then sort(i,r);
end;
procedure xuly_chinh;
var       i,j,k:integer;
begin
  assign(f,fo); rewrite(f);
  sort(1,m);
  fillchar(ok,sizeof(ok),false);
  i:=m+2;
  a[m+1]:=0;
  a[m+2]:=0;
  a[0]:=0;
  max_cost:=0;
  tong_max:=0;
  while a[i]+a[i-1]<=a[i]*m  do
  begin
    dec(i,2);
  max_cost:=a[i];
  tong_max:=max_cost*(m-i+1);
  end;
  write(f,max_cost,' ',tong_max);
  close(f);
end;
begin
  input;
  xuly_chinh;
end.
Nó bị lỗi tràn ở dòng
Code:
dec(i,2)
Bạn xem lại dòng
Code:
 i:=m+2;
.
[RIGHT][I][B]Nguồn: MathScope.ORG[/B][/I][/RIGHT]
 
__________________
SvBk
[Only registered and activated users can see links. ][Only registered and activated users can see links. ]
$\begin{math}
\heartsuit\heartsuit\heartsuit
\end{math}. $
[Only registered and activated users can see links. ]
franciscokison is offline   Trả Lời Với Trích Dẫn
Trả lời Gởi Ðề Tài Mới

Bookmarks

Ðiều Chỉnh
Xếp Bài

Quuyền Hạn Của Bạn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 05:40 PM.


Powered by: vBulletin Copyright ©2000-2024, Jelsoft Enterprises Ltd.
Inactive Reminders By mathscope.org
[page compression: 45.43 k/49.22 k (7.69%)]