program sinhdl; uses crt; const fi='DEFENSE.IN'; N:array[0..9] of integer =…
- User
program sinhdl; uses crt; const fi='DEFENSE.IN'; N:array[0..9] of integer = (10,40,80,100,500,600,700,800,900,1000); test:array[0..9] of integer = (5,6,7,8,9,10,20,21,22,25);
var p,i,t,k:integer; f:text; s:string; BEGIN randomize; for p := 0 to 9 do Begin s:=fi+chr(p+48); assign(f,s); rewrite(f); writeln(f,test[p]); for k:=1 to test[p] do Begin writeln(f,N[p]); for i:=1 to N[p] do write(f,random(1000000)+1,' '); writeln(f); end; close(f); end; END. chuyển sang viết dưới dạng codeblock
- Assistant
Certainly! Converting your Pascal program into a Code::Blocks C++ project involves translating the logic and syntax of Pascal to C++. Here is a version of your Pascal program rewritten in C++:
- Open Code::Blocks and create a new console application project.
- Replace the auto-generated
main.cppcontent with the following code:
- User
program phongthu; const fi='DEFENSE.IN9'; fo='DEFENSE.OU9'; nmax = 1000; var A,F:array[1..nmax] of longint; N:longint; procedure xuly; var test:integer; i,j,k:integer; Max:longint; f1,f2:text; Begin assign(f1,fi); reset(f1); assign(f2,fo); rewrite(f2); readln(f1,test); for k:=1 to test do Begin readln(f1,N); for i:=1 to N do read(f1,A[i]); F[1] := 1; for i:=2 to N do Begin F[i] := 1; for j:=1 to i - 1 do if A[j] < A[i] then if F[i] < F[j] + 1 then F[i] := F[j]+1; end; readln(f1); Max := F[1]; for i:=2 to N do if Max < F[i] then Max := F[i]; writeln(f2,Max); end; close(f2); close(f1); end; BEGIN xuly; END. chuyển viết sang codeblock
- Assistant
- User
program phongthu; const fi='DEFENSE.IN9'; fo='DEFENSE.OU9'; nmax = 1000; var A,F:array[1..nmax] of longint; N:longint; procedure xuly; var test:integer; i,j,k:integer; Max:longint; f1,f2:text; Begin assign(f1,fi); reset(f1); assign(f2,fo); rewrite(f2); readln(f1,test); for k:=1 to test do Begin readln(f1,N); for i:=1 to N do read(f1,A[i]); F[1] := 1; for i:=2 to N do Begin F[i] := 1; for j:=1 to i - 1 do if A[j] < A[i] then if F[i] < F[j] + 1 then F[i] := F[j]+1; end; readln(f1); Max := F[1]; for i:=2 to N do if Max < F[i] then Max := F[i]; writeln(f2,Max); end; close(f2); close(f1); end; BEGIN xuly; END. viết bằng c++
- Assistant