giả sử cho tệp văn bản a có tên là vidu2.inp có cấu trúc như sau .dòng 1 chứa 2 số thực x,y.dòng 2 chứa xâu st.viết ct ghi kq vào tệp b có tên là vidu2.out theo cấu trúc như sau .dòng 1 ghi kq là tích 2 số x và y.dòng 2 ghi kq là xâu st
Bài 4: Tìm số dư của phép chia cho 9. CHIA9.PAS Cho một số nguyên dương N có M chữ số. Yêu cầu: Tìm số dư của phép chia số N cho 9. Dữ liệu vào: Cho trong file văn bản CHIA9.INP, có cấu trúc như sau: - Dòng 1: Ghi số nguyên dương M là số lượng chữ số của số N (1 ≤ M ≤ 100). - Dòng 2: Ghi M chữ số của số N, các chữ số được ghi liền nhau. Dữ liệu ra: Ghi ra file văn bản CHIA9.OUT, theo cấu trúc như sau: - Dòng 1: Ghi số nguyên dương Q, là số dư tìm được. Ví dụ: CHIA9.INP CHIA9.OUT 5 74283 6
Bài 5: Tìm số sát sau - SOSATSAU.PAS Cho số tự nhiên A có N chữ số. Hãy hoán vị các chữ số trong A để thu được số B thoả mãn đồng thời hai điều kiện sau: - B lớn hơn A. - B nhỏ nhất. Dữ liệu vào: Cho trong file SOSATSAU.INP có cấu trúc như sau: - Dòng 1: Ghi số N là số lượng chữ số của A (0a[i-1]. Do đoạn cuối giảm dần, điều này thực hiện bằng cách tìm từ cuối dãy lên đầu gặp chỉ số k đầu tiên thỏa mãn a[k]>a[i-1] (có thể dùng tìm kiếm nhị phân) - Đảo giá trị a[k] và a[i-1] - Lật ngược thứ tự đoạn cuối giảm dần (từ a[i] đến a[k]) trở thành tăng dần + Nếu không tìm thấy tức là toàn dãy đã sắp xếp giảm dần, đây là hoán vị cuối cùng.
Bài 2. MẬT KHẨU. Cu Tí thường xuyên tham gia thi lập trình trên mạng. Vì đạt được thành tích cao nên Tí được gửi tặng một phần mềm diệt virus. Nhà sản xuất phần mềm cung cấp cho Tí một mã số là một dãy gồm các bộ ba chữ số ngăn cách nhau bởi dấu chấm và có chiều dài không quá 255 (kể cả chữ số và dấu chấm). Để cài đặt được phần mềm, Tí phải nhập vào mật khẩu của phần mềm. Mật khẩu là một số nguyên dương M được tạo ra bằng cách tính tổng giá trị các bộ ba chữ số trong dãy mã số, các bộ ba này được đọc từ phải sang trái. - Yêu cầu: Cho biết mã số của phần mềm, hãy tìm mật khẩu của phần mềm đó. - Dữ liệu vào: Cho từ tệp văn bản có tên BL2.INPgồm một dòng chứa xâu ký tự S (độ dài xâu không quá 255 ký tự) là mã số của phần mềm. - Kết quả: Ghi ra tệp văn bản có tên BL2.OUTgồm một số nguyên là mật khẩu tìm được. MK.INP MK.OUT 123.234 257
Bài 6: Biến đổi số BIENDOI.PAS Cho một số nguyên dương M có K chữ số (0 < M; 1 ≤ K ≤ 200). Người ta thực hiện biến đổi số M bằng cách xóa đi trong M các chữ số 0 và sau đó sắp xếp các chữ số còn lại theo thứ tự không giảm của giá trị từng chữ số. Gọi số nguyên dương N là số thu được sau khi thực hiện biến đổi số M. Yêu cầu: Hãy tìm số nguyên dương N. Dữ liệu vào: Nhập vào từ tệp biendoi.inp số M Dữ liệu ra: Ghi ra tệp biendoi.out số N Ví dụ: M=3880247 N=234788
BÀI TẬP THỰC HÀNH – DỮ LIỆU KIỂU TỆP
Câu 1: Cho tệp BAI1.INP có cấu trúc như sau:
- Gồm 1 dòng chứa độ dài 2 cạnh của hình chữ nhật
Em hãy lập chương trình tính diện tích hình chữ nhật đó . Kết quả in ra màn hình đúng đến 2 chữ số thập phân?
Câu 2: Cho tệp BAI2.INP có cấu trúc như sau:
- Gồm 1 dòng chứa độ dài 2 cạnh của hình chữ nhật
Em hãy lập chương trình tính diện tích hình chữ nhật đó . Kết quả ghi vào tệp BAI2.OUT
đúng đến 2 chữ số thập phân?
Câu 3: Cho tệp BAI3.INP có cấu trúc như sau:
- Gồm N dòng chứa độ dài 2 cạnh của hình chữ nhật
Em hãy lập chương trình tính diện tích hình chữ nhật đó . các kết quả ghi vào tệp BAI3.OUT đúng đến 2 chữ số thập phân?
Câu 4: Cho tệp BAI4.INP chứa 3 số nguyên a,b,c lần lượt là độ dài của 3 cạnh tam giác. Hãy lập chương trình tính chu vi, diện tích của tam giác đó .Kết quả ghi vào tệp BAI4.OUT có cấu trúc như sau:
BAI4.INP | BAI4.OUT |
3 4 5 | Chu vi=….. Dien tich =…… |
Câu 5: Cho tệp BAI5.INP chứa duy nhất số nguyên dương M . Hãy lập chương trình kiểm tra M là số chẵn hay số lẻ .Kết quả ghi vào tệp BAI5.OUT có cấu trúc như sau:
BAI5.INP | BAI5.OUT |
7 | 7 la so le |
Câu 6: Cho tệp BAI6.INP có cấu trúc như sau :
-Dòng 1: số nguyên dương N
-Dòng 2: là dãy N số nguyên dương a1, a2, …..an
Hãy lập chương trình ghi vào tệp BAI6.OUT :
-Dòng 1: Dãy số nguyên a1,a2,a3,…,an
-Dòng 2: Các số chẵn của dãy số
-Dòng 3: Số phần tử >10
-Dòng 4: Tổng các phần tử của dãy
BAI6.INP | BAI6.OUT |
5 4 6 23 1 5 | Dãy số nguyên có dạng :4 16 23 1 5 Các số chẵn của dãy số là 4 16 Số phần tử lớn hơn 10 là: 2 Tổng các phần tử của dãy là: 49 |
Câu 7: Cho tệp BAI7.INP có cấu trúc như sau :
-Dòng 1: số nguyên dương N
-Dòng 2: là dãy N số nguyên dương a1, a2, …..an
Hãy lập chương trình ghi vào tệp BAI7.OUT :
-Dòng 1: Dãy số nguyên a1,a2,a3,…,an
-Dòng 2: Các số lẻ của dãy số
-Dòng 3: Số phần tử =0
-Dòng 4: Tổng các phần tử của dãy
BAI7.INP | BAI7.OUT |
8 4 0 6 23 0 1 5 0 | Dãy số nguyên có dạng : 4 0 6 23 0 1 5 0 Các số lẻ của dãy số là 23 1 5 Số phần tử bằng 0 là: 3 Tổng các phần tử của dãy là: 49 |
Câu 1:
uses crt;
const fi='bai1.inp'
var f1:text;
a,b:real;
begin
clrscr;
assign(f1,fi); reset(f1);
readln(f1,a,b);
writeln(a*b:4:2);
close(f1);
readln;
end.
Câu 2:
const fi='bai2.inp'
fo='bai2.out'
var f1,f2:text;
a,b:real;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,a,b);
writeln(f2,a*b:4:2);
close(f1);
close(f2);
end.
Câu 3:
const fi='bai3.inp'
fo='bai3.out'
var f1,f2:text;
a,b:array[1..100]of real;
i,n:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
n:=0;
while not eof(f1) do
begin
n:=n+1;
readln(f1,a[n],b[n]);
end;
for i:=1 to n do
writeln(f2,a[i]*b[i]:4:2);
close(f1);
close(f2);
end.
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Help me!!! Mai mk thi ạ
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?
Cho tệp dulieu.inp chứa các bộ số nguyên ( mỗi bộ ghi trên 1 dòng gồm 2 số nguyên cách nhau bởi 1 kí tự trống). Vt ctrinh đọc dữ liệu trong tệp trên rồi tính tổng của mỗi bộ số nguyên, ghi các kq vào tệp tong.out( mỗi kq trên 1 dòng ). Lưu ý có sd ctrinh con
Viết chương trình sử dụng các hàm và thủ tục xây dựng ở trên để giải bài toán:
Cho tệp dữ liệu TAMGIAC.DAT có cấu trúc như sau:
- Dòng đầu tiên chứa số N;
- N dòng tiếp theo, mỗi dòng chứa 6 số thực xA, yA, xB, yB, xC, yC là tọa độ 3 đỉnh A(xA, yA), B(xB, yB), C(xC, yC) của tam giác ABC
Hãy nhập dữ liệu từ tệpđã cho và trong số N tam giác đó, đưa ra tệp TAMGIAC.OUT gồm 3 dòng:
- Dòng đầu tiên là số lượng tam giác đều;
- Dòng thứ 2 là số lượng tam giác cân (nhưng không là đều);
- Dòng thứ 3 là số lượng tam giác vuông.
const fi='tamgiac.dat'
fo='tamgiac.out'
var f1,f2:text;
a,b,c,d,e,f:array[1..100]of integer;
i,n,dem1,dem2,dem3:integer;
ab,bc,ac:real;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,a[i],b[i],c[i],d[i],e[i],f[i]);
dem1:=0;
dem2:=0;
dem3:=0;
for i:=1 to n do
begin
ab:=sqrt(sqr(a[i]-c[i])+sqr(b[i]-d[i]));
ac:=sqrt(sqr(a[i]-e[i])+sqr(b[i]-f[i]));
bc:=sqrt(sqr(c[i]-e[i])+sqr(d[i]-f[i]));
if (ab>0) and (ac>0) and (bc>0) and (ab+ac>bc) and (ab+bc>ac) and
(ac+bc>ab) then
begin
if (ab=ac) or (ac=bc) then inc(dem1);
if ((ab=ac) and (ab<>bc) and (ac<>bc)) then inc(dem2);
if ((ac=bc) and (bc<>ab) and (ac<>ab)) then inc(dem2);
if ((ac=bc) and (ac<>ab) and (bc<>ab)) then inc(dem2);
if sqr(ab)=sqr(ac)+sqr(bc) then inc(dem3);
if sqr(ac)=sqr(bc)+sqr(ab) then inc(dem3);
if sqr(bc)=sqr(ab)+sqr(ac) then inc(dem3);
end;
end;
writeln(f2,dem1);
writeln(f2,dem2);
writeln(f2,dem3);
close(f1);
close(f2);
end.
Viết chương trình C++ sử dụng các hàm và thủ tục xây dựng ở trên để giải bài toán:
Cho tệp dữ liệu TAMGIAC.DAT có cấu trúc như sau:
- Dòng đầu tiên chứa số N;
- N dòng tiếp theo, mỗi dòng chứa 6 số thực xA, yA, xB, yB, xC, yC là tọa độ 3 đỉnh A(xA, yA), B(xB, yB), C(xC, yC) của tam giác ABC
Hãy nhập dữ liệu từ tệpđã cho và trong số N tam giác đó, đưa ra tệp TAMGIAC.OUT gồm 3 dòng:
- Dòng đầu tiên là số lượng tam giác đều;
- Dòng thứ 2 là số lượng tam giác cân (nhưng không là đều);
- Dòng thứ 3 là số lượng tam giác vuông.
(Viet chuong trinh C++ chu khong phai Pascal a )