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.
#include <bits/stdc++.h>
using namespace std;
long long a[20],b[20],c[20],i,n;
int main()
{
cin>>n;
srand(time(NULL));
for (i=1; i<=n; i++)
a[i]=rand();
srand(time(NULL));
for (i=1; i<=n; i++)
b[i]=rand();
for (i=1; i<=n; i++)
c[i]=abs(a[i]-b[i]);
for (i=1; i<=n; i++) cout<<a[i]<<" "; cout<<endl;
for (i=1; i<=n; i++) cout<<b[i]<<" "; cout<<endl;
for (i=1; i<=n; i++) cout<<c[i]<<" "; cout<<endl;
return 0;
}
Bài 1:
uses crt;
var n,kt,d:integer;
st:string;
begin
clrscr;
write('Nhap bien so xe:'); readln(n);
str(n,st);
d:=length(st);
kt:=0;
if (st[d-1]='6') and (st[d]='8') then kt:=1;
if kt=0 then writeln('Day khong la bien so dep')
else writeln('Day la bien so xe dep');
readln;
end.
Bài 2:
uses crt;
var a,b,c:array[1..100]of integer;
n,i,min,x,t,dem,j,dem1,kt,max,min1,y,kt1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Mang vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('Phan tu nho nhat trong mang la: ',min);
write('Nhap i='); readln(y);
for i:=1 to n do
if y=i then
begin
t:=0;
dem:=0;
for j:=1 to a[i] do
if a[i] mod j=0 then
begin
t:=t+j;
dem:=dem+1;
b[dem]:=j;
end;
end;
writeln('Cac uoc cua phan tu a[',y,'] trong mang la: ');
for i:=1 to dem do
write(b[i]:4);
writeln;
writeln('Tong cac uoc cua phan tu a[',y,'] trong mang la: ',t);
dem1:=0;
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then
begin
inc(dem1);
c[dem1]:=a[i];
end;
end;
max:=c[1];
min1:=c[1];
for i:=1 to dem1 do
begin
if max<c[i] then max:=c[i];
if min1>c[i] then min1:=c[i];
end;
writeln('Tong cua so nguyen to lon nhat va so nguyen to nho nhat trong mang la: ',max+min1);
write('Nhap x='); readln(x);
kt1:=0;
for i:=1 to n do
begin
if i<x then
begin
for j:=i to x do
if a[j]<>a[x-j+1] then kt1:=1;
end;
end;
if kt1=0 then writeln('Khong co ',x,' so doi xung dung canh nhau')
else writeln('Co ',x,' so doi xung dung canh nhau');
readln;
end.
#include <iostream>
#include <fstream>
using namespace std;
long int x[4],n,a[5001],kt[5001],ktvt[5001],MAXtong,dem=0;
int TRY(int i)
{
for(int j=x[i-1]+1;j<=n;j++)
if(kt[a[j]]==0)
{
x[i]=j;
kt[a[j]]=1;
if(i==3)
{
if(a[x[3]]==(float)(a[x[2]]+a[x[1]])/2||a[x[2]]==(float)(a[x[3]]+a[x[1]])/2||a[x[1]]==(float)(a[x[2]]+a[x[3]])/2)
{
dem++;
if(a[x[1]]+a[x[2]]+a[x[3]]>MAXtong)
{
MAXtong=a[x[1]]+a[x[2]]+a[x[3]];
}
}
}
else
TRY(i+1);
kt[a[j]]=0;
}
}
int main()
{
ifstream f("boba.inp");
f>>n;
for(int i=1;i<=n;i++)
{
f>>a[i];
}
x[0]=0;
MAXtong=-1000000000;
fill_n(kt,1001,0);
TRY(1);
cout<<dem<<endl;
if(dem>0)
{
cout<<MAXtong;
}
return 0;
}
Mình mới đạt tới trình độ quy hoạch động nên bạn thông cảm
Xin lỗi bạn, mình không hỗ trợ C. mình chỉ biết pascal thôi
const fi='tamhop.inp';
fo='tamhop.out';
var f1,f2:text;
a:array[1..100]of integer;
n,i,j,k,dem,max,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
{--------------------------------xu-ly--------------------------------}
dem:=0; max:=0;
for i:=1 to n-2 do
begin
for j:=i+1 to n-1 do
begin
for k:=j+1 to n do
begin
if (a[i]=(a[j]+a[k])/2) or (a[j]=(a[i]+a[k])/2) or (a[k]=(a[i]+a[j])/2) then
begin
inc(dem);
t:=a[i]+a[j]+a[k];
if max<=t then max:=t;
end;
end;
end;
end;
writeln(f2,dem);
writeln(f2,max);
close(f1);
close(f2);
end.