cho tệp văn bản XAU.INP lưu trũ họ tên của các học sinh trong lớp. Mỗi học sinh được lưu trữ trên một dòng. Viết chương trình đọc dữ liệu từ tệp XAU.INP, kết quả ghi vào XAU.OUT là độ dài tên từng học sinh trong lớp
tệp xau.inp gồm các dòng kí tự, mỗi dòng không vượt quá 255 kí tự. viết chương trình đọc dữ liệu từ tệp xau.inp. đếm số kí tự là chữ'a'. ghi kết quả ra tệp xau.out chứa số nguyên duy nhất là số lượng kí tự'a' có trong tệp xau.inp
#include <bits/stdc++.h>
using namespace std;
string st;
int d,i,dem;
int main()
{
freopen("xau.inp","r",stdin);
freopen("xau.out","w",stdout);
cin>>st;
d=st.length();
dem=0;
for (i=0; i<=d-1; i++)
if (st[i]=='a') dem++;
cout<<dem;
return 0;
}
Cho 2 tệp in.txt và out.txt:
1. Trên tệp in.txt lưu giá trị n, tính n! sau đó ghi lại kết quả vào tệp out.txt
2. Trên tệp in.txt ghi tên 4 học sinh trên 4 dòng, đọc và ghi lại tên của các học sinh đó trên tệp out.txt
Bài 1:
Program HOC24;
const fi='in.txt'
fo='out.txt'
var f: text;
i,n: integer;
t: longint;
procedure ip;
begin
assign(f,fi);
reset(f);
read(f,n);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
t:=1;
for i:=1 to n do t:=t*i;
write(f,t);
close(f);
end;
begin
ip;
out;
end.
Bài 2:
Program HOC24;
const fi='in.txt'
fo='out.txt'
var f: text;
i: byte;
a: array[1..4] of string;
procedure ip;
begin
assign(f,fi);
reset(f);
for i:=1 to 4 do readln(f,a[i]);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
for i:=1 to 4 do writeln(f,a[i]);
close(f);
end;
begin
ip;
out;
end.
1:
const fi='inp.txt'
fo='out.txt'
var n,i:integer;
s:real;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
s:=1;
for i:=1 to n do
s:=s*i;
writeln(f2,s:4:2);
close(f1);
close(f2);
end.
Cho tệp SN3.INP chứa n số nguyên dương (mỗi số cách nhau một dấu cách trên một dòng). Viết chương trình đọc dữ liệu từ tệp đã cho Tính ƯCLN dãy các số nguyên dương đó và lưu kết quả vào tệp UC.OUT .
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[1000],i,n,uc;
//chuongtrinhcon
unsigned long long ucln(long long a,long long b)
{
if (b==0) return(a);
else return(ucln(b,a%b));
}
//chuongtrinhchinh
int main()
{
freopen("sn3.inp","r",stdin);
freopen("uc.out","w",stdout);
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
uc=ucln(a[1],a[2]);
for (i=3; i<=n; i++)
uc=ucln(uc,a[i]);
cout<<uc;
return 0;
}
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)?
Viết chương trình C++. Mỗi cơ sở giáo dục có một số lượng học sinh ai dự thi khác nhau. Dữ liệu vào: Cho từ tệp văn bản GIAODUC.INP gồm 1 dòng duy nhất là các phần tử ai (1< ai
Cho 1 tệp có tên là mang.txt viết chương trình đọc dữ liệu từ tệp sau đó tính tổng các giá trị đọc được ghi vào tệp tong.txt
const fi='mang.txt'
fo='tong.txt'
var f1,f2:text;
a:array[1..100]of integer;
n,i,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewriteln(f2);
n:=0;
while not eof(f1) do
begin
inc(n);
read(f1,a[n]);
end;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.