Những câu hỏi liên quan
Nguyễn Công Bằng
Xem chi tiết
APOK FF
Xem chi tiết
thiên thanh
Xem chi tiết
89654DAUUBUOIIIII956
Xem chi tiết
Phía sau một cô gái
26 tháng 7 2023 lúc 19:45

#include <iostream>

#include <map>

using namespace std;

int main() {

       int n;

       cin >> n;

       map<int, int> count;

       for (int i = 0; i < n; i++) {

              int x;

              cin >> x;

              count[x]++;

       }

       int ans = 0;

       for (auto p : count) {

              int x = p.second;

              ans += (x * (x - 1)) / 2;

       }

       cout << ans;

       return 0;

}

Bình luận (1)
Cao Phạm Hà Anh
Xem chi tiết
Nguyễn Lê Phước Thịnh
18 tháng 8 2023 lúc 12:12

const fi='docao13.inp'

fo='docao13.out'

var f1,f2:text;

a:array[1..100]of integer;

i,n:integer;

//chuongtrinhcon

function kq(x:integer):integer;

var t,k:integer;

begin

t:=0;

while (x>0) do

begin

k:=x mod 10;

t:=t+k;

x:=x div 10;

end;

kq:=t;

end;

//chuongtrinhchinh

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

readln(f1,n);

for i:=1 to n do 

read(f1,a[i]);

for i:=1 to n do

write(f2,kq(a[i]):4);

close(f1);

close(f2);

end.

Bình luận (0)
Lê Phương Thảo
Xem chi tiết
Nguyễn Lê Phước Thịnh
25 tháng 2 2021 lúc 21:55

uses crt;

var a:array[1..250]of integer;

i,n,dem,t,t1,t2,t3,t4:integer;

begin

clrscr;

repeat

write('Nhap n='); readln(n);

until (0<n) and (n<=250);

for i:=1 to n do 

  begin

repeat

write('A[',i,']='); readln(a[i]);

until (0<a[i]) and (a[i]<=500);

end;

dem:=0;

for i:=1 to n do 

  if a[i] mod 2=1 then inc(dem);

writeln('So phan tu co gia tri le la: ',dem);

t:=0;

for i:=1 to n do 

  if i mod 2=0 then t:=t+a[i];

writeln('Tong cac phan tu co chi so chan la: ',t);

t1:=0;

for i:=1 to n do 

  if i mod 2=1 then t1:=t1+a[i];

writeln('Tong cac phan tu co chi so le la: ',t1);

t2:=0;

for i:=1 to n do 

  if (i mod 2=0) and (a[i] mod 2=0) then t2:=t2+a[i];

writeln('Tong cac phan tu chan co chi so chan la: ',t2);

t3:=0;

for i:=1 to n do 

  if (i mod 2=1) and (a[i] mod 2=1) then t3:=t3+a[i];

writeln('Tong cac phan tu co chi so le la: ',t3);

t4:=0;

for i:=1 to n do 

  t4:=t4+a[i];

writeln('Trung binh cong cac so trong day la: ',t4/n:4:2);

readln;

end.

Bình luận (0)
Nguyễn Phương Oanh
Xem chi tiết
Ngọc Ty
Xem chi tiết
Kiều Vũ Linh
24 tháng 4 2023 lúc 18:56

Var a:array[1..100] of integer;

i,n:integer;

s:longint;

Begin

Write('n = ');readln(n);

For i:=1 to n do

Begin

Write('Nhap phan tu thu ',i,' = ');readln(a[i]);

s:=s+a[i];

End;

Write('Cac phan tu vua nhap la ');

For i:=1 to n do

Write(a[i]:8);

Writeln;

Write('Tong cua chung la ',s);

Readln

End.

Bình luận (0)
Xem chi tiết
Nguyễn Thị Thùy Trang
13 tháng 2 2022 lúc 21:37

Ý tưởng: Tìm số lớn nhất trong hai dãy đã cho. Không mất tính tổng quát, giả sử số lớn nhất của 2 dãy nằm trong dãy a, ta xét các số trong dãy b, tại vị trí i:  nếu a[i] < b[i] thì hoán vị a[i] và b[i]. Sau đó tìm số lớn nhất trong dãy b rồi nhân với số lớn nhất của hai dãy sẽ ra được kết quả. 

#include <iostream>

using namespace std;

#define maxN 105

 

int main() {

int a[maxN], b[maxN];

int t;

cin >> t;

while (t--)

{

int n;

cin >> n;

int maxA = 0, maxB = 0;

for (int i = 0; i < n; i++)

{

cin >> a[i]; maxA = max(a[i], maxA);

}

for (int i = 0; i < n; i++)

{

cin >> b[i]; maxB = max(b[i], maxB);

}

if (maxA < maxB) 

swap(a, b);

int maxV = max(maxA, maxB);

for (int i = 0; i < n; i++)

if (b[i] > a[i]) 

swap(b[i], a[i]);

maxB = 0;

for (int i = 0; i < n; i++)

maxB = max(b[i], maxB);

cout << maxB * maxV << endl;

}

return 0;

}

Bình luận (0)