Những câu hỏi liên quan
An Pham
Xem chi tiết
Tiện Tiện
Xem chi tiết
nguyễn an phát
24 tháng 5 2021 lúc 11:06

program tinh_so_lan_xuat_hien;

uses crt;

var i,n,x,d:integer;

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

begin

clrscr;

write('nhap n:');readln(n);

for i:=1 to n do

begin

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

end;

d:=0;

write('nhap x:');readln(x);

for i:=1 to n do

if x=a[i] then inc(d);

writeln(x,' xuat hien ',d,' lan trong mang a');

readln;

end.

Bình luận (0)
Lala
Xem chi tiết
Trương Huy Hoàng
13 tháng 12 2023 lúc 22:58

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll> mp;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    freopen("MAP1.INP","r",stdin);
    freopen("MAP1.OUT","w",stdout);
    ll n; cin >> n;
    ll a[n+5];
    for(ll i=1;i<=n;i++) cin >> a[i], mp[a[i]]++;
    for(pair<ll,ll> it:mp) cout << it.first << " " << it.second << "\n";
}

Chúc bạn học tốt!

Bình luận (0)
No_sun
Xem chi tiết
Gia Huy
26 tháng 6 2023 lúc 15:29

```
n, k = map(int, input().split())
a = list(map(int, input().split()))

count = 0
for i in range(n):
if a[i] == k:
count += 1

print(count)
```

giải thích: dòng đầu đọc vào số n và giá trị k, dòng hai đọc vào mảng a. Biến count được khởi tạo bằng 0 để đếm số lần xuất hiện của giá trị k trong mảng a. Vòng lặp for duyệt qua từng phần tử trong mảng a. Nếu phần tử đó bằng k => tăng biến count lên 1. Sau cùng, in ra giá trị của biến count.

Ví dụ:

Input:
```
5 2
1 2 3 2 4
```

Output:
```
2
```

(Giá trị 2 xuất hiện 2 lần trong mảng [1, 2, 3, 2, 4].)

Bình luận (1)
Nguyễn Hoàng Duy
27 tháng 6 2023 lúc 10:03

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, x;
    cin >> n >> x;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == x){
            count++;
        }
    }
    cout << count << endl;
}

 

Bình luận (0)
Đặng Nguyễn Hoài Băng
Xem chi tiết

#include <bits/stdc++.h>
using namespace std;
int n,x,i,cnt,res=0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>x;
for(i=0;i<n;i++)
{
    cin>>cnt;
    if(cnt==x) res++;
}
cout<<"so luong xuat hien so "<<x<<" la: "<<res;
return 0;
}

 

 

Bình luận (0)
HOÀNG ĐẠI PHÚC
Xem chi tiết
quang cảnh lê
Xem chi tiết
Nguyễn Lê Phước Thịnh
27 tháng 2 2021 lúc 11:02

uses crt;

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

i,n,x,dem:integer;

begin

clrscr;

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

for i:=1 to n do 

 begin

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

end;

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

dem:=0;

for i:=1 to n do 

if a[i]=x then inc(dem);

writeln(dem);

readln;

end.

Bình luận (0)
Nguyen Bảo Nhi
Xem chi tiết
Nguyễn Lê Phước Thịnh
8 tháng 4 2021 lúc 20:14

uses crt;

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

i,n,k,h,dem,t,dem1,dem2,t1,t2:integer;

begin

clrscr;

for i:=1 to 100 do 

  begin

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

end;

n:=100;

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

for i:=1 to n do 

  if a[i]=k then write(i:4);

writeln;

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

dem:=0;

for i:=1 to n do 

  if a[i]=h then inc(dem);

writeln(h,' xuat hien ',dem,' lan trong mang');

t:=0;

for i:=1 to n do 

  t:=t+a[i];

writeln('Tong cac phan tu cua day la: ',t);

dem1:=0;

t1:=0;

dem2:=0;

t2:=0;

for i:=1 to n do 

  begin

if a[i]>0 then

begin

inc(dem1);

t1:=t1+a[i];

end;

if a[i]<0 then 

begin

inc(dem2);

t2:=t2+a[i];

end;

end;

writeln('Co ',dem1,' so duong');

writeln('Tong cac so duong la: ',t1);

writeln('Co ',dem2,' so am');

writeln('Tong cac so am la: ',t2);

readln;

end. 

Bình luận (0)
Nguyễn Trần Cảnh Nam
8 tháng 4 2021 lúc 22:07

bằng c++ hay pascal?

 

Bình luận (1)
Bình Nguyễn
Xem chi tiết
Nguyễn Lê Phước Thịnh
5 tháng 12 2019 lúc 23:33

2:

uses crt;
var a:array[1..100]of integer;
i,j,n,dem:byte;
tam,x,d:integer;
begin
clrscr;
write('nhap so phan tu:'); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------------------------}
for i:=1 to n do write(a[i]:4);
{-----------------xu-ly-dem-so-x----------------------}
writeln;
d:=0;
write('x='); readln(x);
for i:=1 to n do
if a[i]=x then d:=d+1;
writeln('so lan xuat hien cua ',x,' trong day la: ',d);
{---------------------------------------------------}
writeln;
i:=1;
while i<=n do
begin
write(a[i],' xuat hien ');
dem:=1;
while a[i]=a[i+1]do
begin
inc(dem);
inc(i);
end;
inc(i);
writeln(dem,' lan');
end;
readln;
end.

3:

uses crt;
var a,b:array[1..100]of integer;
i,n,x,dem,y:integer;
begin
clrscr;
write('nhap so phan tu:'); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------------------------}
for i:=1 to n do write(a[i]:4);
{-----------------xu-ly-dem-so-x----------------------}
writeln;
write('x='); readln(x);
write('nhap so can thay the: '); readln(y);
dem:=0;
for i:=1 to n do
if a[i]=x then
begin
inc(dem);
b[dem]:=i;
a[i]:=y;
end;
writeln('cac vi tri cua ',x,' trong day A la: ');
for i:=1 to dem do
write(b[i]:4);
writeln;
writeln('mang sau khi chen la: ');
for i:=1 to n do
write(a[i]:4);
readln;
end.

Bình luận (0)
 Khách vãng lai đã xóa
Nguyễn Lê Phước Thịnh
5 tháng 12 2019 lúc 23:36

4:

uses crt;
var a,b:array[1..30]of integer;
i,n,tam,j:integer;
begin
clrscr;
write('nhap so phan tu:'); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-----------------xu-ly----------------------}
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]<a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
writeln('5 phan tu co gia tri cao nhat trong day la: ');
for i:=1 to 5 do
write(a[i]:4);
readln;
end.

5:

uses crt;
var a:array[1..10]of integer;
i,n,t,t1:integer;
begin
clrscr;
randomize;
write('nhap so phan tu:'); readln(n);
for i:=1 to n do
a[i]:=random(11);
{-----------------xu-ly----------------------}
t:=0;
t1:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then t:=t+a[i];
if i mod 2=1 then t1:=t1+a[i];
end;
writeln('tong cac phan tu co gia tri chan la: ',t);
writeln('tong cac phan tu o vi tri le trong day la: ',t1);
readln;
end.

Bình luận (0)
 Khách vãng lai đã xóa