Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
const fi='nix.inp';
fo='nix.out';
var
f:text;
j,i,n,max:0..100;
a,b,l,m: array [0..101] of integer;
procedure ip;
begin
assign(f,fi);
reset(f);
readln(f,n);
for i:= 1 to n do
read(f,a[i]);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
for i:= 0 to n do
l[i] := 1;
for i:= 1 to n do
for j:= i to n do
if (a[j] > a[i] ) and (l[j] < l[i] + 1 ) then
begin
l[j] := l[i] + 1;
m[j]:= i;
end;
max:=0;
for i:= 1 to n do
if l[i] > max then
begin
j:=i;
max:=l[i];
end;
while m[j] <> 0 do
begin
l[j]:=-l[j];
j:=m[j];
end;
l[j]:=-l[j];
for i:= 1 to n do
if l[i] < 0 then write(f,i,' ');
close(f);
end;
BEGIN
ip;
out;
END.
#include <iostream>
#include <fstream>
int main()
{
std::ifstream f("daycon.inp");
int n,s,a[1001],d[100][1001];
f>>n>>s;
for(int i=1;i<=n;i++)
{
f>>a[i];
}
d[0][0]=0;
a[0]=0;
d[1][a[1]]=1;
for(int i=2;i<=n;i++)
{
for(int j=0;j<=s;j++)
{
d[i][j]=d[i-1][j];
if(j==a[i]&&d[i-1][j]<1)
d[i][j]=1;
else
if(a[i]<j&&d[i-1][j-a[i]]>0&&d[i-1][j-a[i]]+1>d[i][j])
d[i][j]=d[i-1][j-a[i]]+1;
}
}
for(int i=n;i>=1;i--)
{
if(d[i][s]!=d[i-1][s])
{
std::cout<<a[i]<<" ";
s-=a[i];
}
}
return 0;
}
Câu 1:
uses crt;
var b:array[1..100]of integer;
m,i:integer;
begin
clrscr;
write('nhap m='); readln(m);
for i:=1 to m do
begin
write('b[',i,']='); readln(b[i]);
end;
writeln('cac so chan va la boi cua 4 la: ');
for i:=1 to m do
if (b[i] mod 2=0) and (b[i] mod 4=0) then write(b[i]:4);
readln;
end.
Câu 2:
uses crt;
var s:string;
d,kt,i:integer;
begin
clrscr;
write('nhap xau S:'); readln(s);
d:=length(s);
kt:=0;
for i:=1 to d do
if (s[i] in ['A'..'Z']) or (s[i] in ['a'..'z']) then
begin
kt:=1;
write(s[i]:4);
end;
if kt=0 then writeln('Khong co ky tu nao la chu cai trong xau');
readln;
end.
m xàm