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.
Bài 1:
uses crt;
var n,i,dem,maxd,vt,vt1,vt2,vt3,maxa,dem1:integer;
a,b,c,d,e,f,g:array[1..100]of integer;
mind,mina:int64;
begin
clrscr;
repeat
write('n='); readln(n);
if (n<=0) or (n>100) then writeln('nhap lai');
until (0<n) and (n<=100);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{--------------------------so-hang-duong-----------------------}
dem:=0;
for i:=1 to n do
if a[i]>0 then
begin
inc(dem);
b[dem]:=a[i];
end;
maxd:=0;
for i:=1 to dem do
if maxd<b[i] then maxd:=b[i];
vt:=0;
for i:=1 to n do
if maxd=a[i] then
begin
vt:=vt+1;
c[vt]:=i;
end;
writeln('so hang duong lon nhat cua day la: ',maxd);
writeln('vi tri cua no lan luot la: ');
for i:=1 to vt do
write(c[i]:4);
writeln;
mind:=maxint;
for i:=1 to dem do
if mind>b[i] then mind:=b[i];
vt1:=0;
for i:=1 to n do
if mind=a[i] then
begin
inc(vt1);
d[vt1]:=i;
end;
writeln('so hang duong nho nhat cua day la: ',mind);
writeln('vi tri cua no lan luot la: ');
for i:=1 to vt1 do
write(d[i]:4);
{------------------------so-hang-am--------------------------}
writeln;
dem1:=0;
for i:=1 to n do
if a[i]<0 then
begin
inc(dem1);
e[dem1]:=a[i];
end;
maxa:=e[1];
for i:=1 to dem1 do
if maxa<e[i] then maxa:=e[i];
vt2:=0;
for i:=1 to n do
if maxa=a[i] then
begin
inc(vt2);
f[vt2]:=i;
end;
writeln('so hang am lon nhat cua day la: ',maxa);
writeln('vi tri cua no lan luot la: ');
for i:=1 to vt2 do
write(f[i]:4);
writeln;
mina:=maxint;
for i:=1 to dem1 do
if mina>e[i] then mina:=e[i];
vt3:=0;
for i:=1 to n do
if mina=a[i] then
begin
inc(vt3);
g[vt3]:=i;
end;
writeln('so hang am nho nhat cua day la: ',mina);
writeln('vi tri cua no lan luot la: ');
for i:=1 to vt3 do
write(g[i]:4);
readln;
end.
Bài 2:
uses crt;
var a,vt:array[1..10]of integer;
i,x,dem:integer;
begin
clrscr;
for i:=1 to 10 do
begin
write('a[',i,']='); readln(a[i]);
end;
write('nhap x='); readln(x);
dem:=0;
for i:=1 to 10 do
if a[i]=x then
begin
inc(dem);
vt[dem]:=i;
end;
if dem=0 then writeln('khong co gia tri ',x,' trong day')
else
begin
writeln('vi tri cua ',x,' trong day lan luot la:');
for i:=1 to dem do
write(vt[i]:4);
end;
readln;
end.
Bài 3:
uses crt;
var a:array[1..100,1..100]of integer;
n,i,j,t:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
for j:=1 to n do
begin
write('a[',i,',',j,']='); readln(a[i,j]);
end;
{----------------------------xuat-----------------------------}
writeln('ma tran ban vua nhap la:');
for i:=1 to n do
begin
for j:=1 to n do
write(a[i,j]:4);
writeln;
end;
{------------------tong-cac-phan-tu-tren-duong-cheo-chinh------------------}
t:=0;
for i:=1 to n do
for j:=1 to n do
if i=j then t:=t+a[i,j];
writeln('tong cac phan tu tren duong cheo chinh la: ',t);
readln;
end.
uses crt;
var a:array[1..350]of integer;
n,i,t,max,t1:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{------------------------------cau-a----------------------------}
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('tong cac phan tu vua nhap la: ',t);
{------------------------------cau-b----------------------------}
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('so lon nhat cua day la: ',max);
writeln('vi tri cua no lan luot la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
{------------------------------cau-c----------------------------}
writeln;
writeln('cac so chia het cho 3 co trong day la: ');
t1:=0;
for i:=1 to n do
if a[i] mod 3=0 then
begin
write(a[i]:4);
t1:=t1+a[i];
end;
{------------------------------cau-d---------------------------}
writeln;
writeln('tong cac so chia het cho 3 co trong day la: ',t1);
readln;
end.
uses crt;
var a,b,k,dem,x,y:longint;
begin
clrscr;
readln(a,b,k);
dem:=0;
for x:=1 to k do
for y:=1 to k do
if ((a<=b) and (a<=x*x) and (a<=y*y*y)) then dem:=dem+1;
writeln(dem);
readln;
end.
#include <iostream>
#include <vector>
using namespace std;
pair<int, int> findMaxSubarray(vector<int> nums) {
int n = nums.size();
int maxSum = nums[0];
int currentSum = nums[0];
int start = 0;
int end = 0;
for (int i = 1; i < n; i++) {
if (currentSum < 0) {
currentSum = nums[i];
start = i;
end = i;
} else {
currentSum += nums[i];
end = i;
}
if (currentSum > maxSum) {
maxSum = currentSum;
}
}
return make_pair(start, end);
}
int main() {
int numTests;
cin >> numTests;
for (int t = 0; t < numTests; t++) {
int n;
cin >> n;
vector<int> nums(n);
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
pair<int, int> maxSubarray = findMaxSubarray(nums);
cout << maxSubarray.first << " " << maxSubarray.second << endl;
}
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,k,t:integer;
begin
clrscr;
readln(n,k);
for i:=1 to n do readln(a[i]);
t:=0;
for i:=1 to n do
if a[i] mod k=0 then t:=t+a[i];
writeln(t);
readln;
end.