Những câu hỏi liên quan
Sự tâm
Xem chi tiết
TRIẾT PHẠM
Xem chi tiết
Nguyen Thanh Tam
Xem chi tiết
HUY
Xem chi tiết
Nguyễn Lê Phước Thịnh
15 tháng 12 2022 lúc 15:37

#include <bits/stdc++.h>

using namespace std;

int n,s,i,t;

int main()

{

freopen("bai1.inp","r",stdin);

freopen("bai1.out","w",stdout);

cin>>n>>s;

t=0;

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

{

int x;

cin>>x;

if (x%s==0) t+=x;

}

cout<<t;

}

Bình luận (0)
huynh chinh
Xem chi tiết
Nguyễn Lê Phước Thịnh
4 tháng 4 2022 lúc 21:49

#include <bits/stdc++.h>

using namespace std;

long long a[1000],n,i;

int main()

{

freopen("dayd.inp","r",stdin);

freopen("dayd.out","w",stdout);

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

for (i=1; i<=n; i++)

if (a[i]>0) cout<<a[i]<<" ";

return 0;

}

Bình luận (0)
huynh chinh
Xem chi tiết
Nguyễn Lê Phước Thịnh
31 tháng 3 2022 lúc 22:48

#include <bits/stdc++.h>

using namespace std;

long long a[10000],i,n,t;

int main()

{

freopen("avg.inp","r",stdin);

freopen("avg.out","w",stdout);

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

t=0;

for (i=1; i<=n; i++) t+=a[i];

cout<<fixed<<setprecision(1)<<(t*1.0)/(n*1.0);

return 0;

}

Bình luận (0)
Đặng Minh quân
Xem chi tiết
Nguyễn Lê Phước Thịnh
12 tháng 5 2021 lúc 18:41

uses crt;

const fi='dulieu.inp'

var f1:text;

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

n,i,t1,t2:integer;

begin

clrscr;

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

readln(f1,n);

for i:=1 to n do 

  read(f1,a[i]);

t1:=0;

t2:=0;

for i:=1 to n do 

 begin

if a[i]>0 then t1:=t1+a[i];

if a[i]<0 then t2:=t2+a[i];

end;

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

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

close(f1);

readln;

end.

Bình luận (0)
Quang Bui Thanh
Xem chi tiết
Nguyễn Văn Tuyên
30 tháng 12 2023 lúc 11:28

def count_pairs_divisible_by_3(arr):
    n = len(arr)
    
    # Đếm số lượng số dư khi chia cho 3
    count_mod = [0, 0, 0]
    for num in arr:
        count_mod[num % 3] += 1

    # Trường hợp 0: Số dư 0 + Số dư 0
    count_pairs = count_mod[0] * (count_mod[0] - 1) // 2

    # Trường hợp 1: Số dư 1 + Số dư 2
    count_pairs += count_mod[1] * count_mod[2]

    # Trường hợp 2: Số dư 1 + Số dư 1 hoặc Số dư 2 + Số dư 2
    count_pairs += count_mod[1] * (count_mod[1] - 1) // 2
    count_pairs += count_mod[2] * (count_mod[2] - 1) // 2

    return count_pairs

# Thử nghiệm
arr = [3, 5, 7, 9, 11, 13, 15]
result = count_pairs_divisible_by_3(arr)
print(f"Số lượng cặp số có tổng chia hết cho 3 là: {result}"

Bình luận (0)
Asuna
Xem chi tiết

Dưới đây là mã chương trình Pascal để sắp xếp dãy số theo yêu cầu đã cho:

```pascal
program sorting;

const
MAX_N = 1000;

var
N, i, j, temp: integer;
arr: array[1…MAX_N] of integer;
oddArr, evenArr: array[1…MAX_N] of integer;
oddCount, evenCount: integer;
inputFile, outputFile: text;

begin
// Mở file input và đọc dữ liệu
assign(inputFile, 'sorting.inp');
reset(inputFile);
readln(inputFile, N);
for i := 1 to N do
read(inputFile, arr[i]);
close(inputFile);

// Sắp xếp mảng theo yêu cầu
oddCount := 0;
evenCount := 0;
for i := 1 to N do
begin
if arr[i] mod 2 = 1 then
begin
oddCount := oddCount + 1;
oddArr[oddCount] := arr[i];
end
else
begin
evenCount := evenCount + 1;
evenArr[evenCount] := arr[i];
end;
end;

// Sắp xếp mảng số lẻ tăng dần
for i := 1 to oddCount - 1 do
for j := i + 1 to oddCount do
if oddArr[i] > oddArr[j] then
begin
temp := oddArr[i];
oddArr[i] := oddArr[j];
oddArr[j] := temp;
end;

// Sắp xếp mảng số chẵn giảm dần
for i := 1 to evenCount - 1 do
for j := i + 1 to evenCount do
if evenArr[i] < evenArr[j] then
begin
temp := evenArr[i];
evenArr[i] := evenArr[j];
evenArr[j] := temp;
end;

// Mở file output và ghi kết quả
assign(outputFile, 'sorting.out');
rewrite(outputFile);
for i := 1 to oddCount do
write(outputFile, oddArr[i], ' ');
writeln(outputFile);
for i := 1 to evenCount do
write(outputFile, evenArr[i], ' ');
close(outputFile);
end.
```

Bạn có thể sao chép mã chương trình trên vào một tệp tin có tên `sorting.pas`, sau đó tạo một tệp tin `sorting.inp` và nhập dữ liệu theo định dạng đã cho. Chạy chương trình và kết quả sẽ được ghi vào tệp tin `sorting.out`.

Bình luận (0)
Phạm Dương Phúc Khang
21 tháng 1 lúc 22:55

var i,n:longint; a:array[1..1000] of longint;

begin

readln(n);

for i:=1 to n do read(a[i]);

for i:=1 to n do

     if a[i] mod 2=0 then 

         begin

              inc(k);

              b[k]:=a[i];

         end

else

begin

inc(t);

c[t]:=a[i];

end;

for i:=1 to k-1 do

for j:=i+1 to k do

if b[i]<b[j] then

begin

d:=b[i];

b[i]:=b[j];

b[j]:=d;

end;

for i:=1 to  t-1 do

for j:=i+1 to t do

if c[i]>c[j] then

begin

d:=c[i];

c[i]:=c[j];

c[j]:=d;

end;

for i:=1 to k do write(b[i],' ');

for i:=1 to t do write(c[i],' ');

end.

Bình luận (0)