Giúp mình với ạ Viết chương trình nhập từ bàn phím xâu A, in ra màn hình xâu vừa nhập và mỗi kí tự của xâu trên một hàng?
Nhập xâu
for i in range(len(a)):
print(a[i])
Bài tập 2:Viết chương trình nhập một xâu từ bàn phím. Đếm số kí tự là chữ số chữ cái trong xâu vừa nhập và in ra màn hình. Xóa các chữ số kh xâu vừa nhập
2:
uses crt;
var st:string;
d,i,dem1,dem2:integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
dem1:=0;
dem2:=0;
for i:=1 to d do
begin
if st[i] in ['0'..'9'] then inc(dem1);
if (st[i] in ['a'..'z']) or (st[i] in ['A'..'Z']) then inc(dem2);
end;
writeln('So ki tu la chu so la: ',dem1);
writeln('So ki tu la chu cai la: ',dem2);
for i:=1 to d do
if st[i] in ['0'..'9'] then delete(st,i,1);
writeln('Xau sau khi xoa cac chu so la: ',st);
readln;
end.
Viết chương trình nhập vào từ bàn phím một xâu kí tự. In ra màn hình xâu gồm tất cả các kí tự chữ số lấy từ xâu đã nhập
Var s,st:string;
i:integer;
Begin
Write('Nhap xau ');readln(s);
For i:=1 to length(s) do
If s[i] in ['0'..'9'] then st:=st+s[i];
Write('Cac ki tu so co trong day la ',st);
Readln
End.
giúp em với sáng mai em thi rồi..
1.viết chương trình nhập vào một xâu kí tự từ bàn phím. in ra màn hình xâu kí tự sau khi đã thay các từ "nang" thành "mua".
2. viết chương trình vào một xâu kí tự từ bàn phím .kiểm tra xem xâu đó có phải là xâu palindrom không? ( Xâu palindrom là xâu khi viết từ trái qua phải cũng giống như từ phải qua trái, VD: Xâu 'ABBA' là một xâu palindrom).
giúp em với ạ em rất cần gấp
Bài 1:
uses crt;
var S:String;
vt:integer;
begin
clrscr;
Write(‘Nhap 1 xau:’); Readln(S);
While pos(‘nang’,s)>0 do
Begin
Vt:= pos(‘nang’,s);
Delete(s,vt,4);
Insert(‘mua’,s ,vt);
End;
Writeln(‘Xau sau khi thay the ’,s);
Readln;
End.
Bài 2:
uses crt;
var st:string;
d,i,kt:integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
kt:=0;
for i:=1 to d do
if st[i]<>st[d-i+1] then kt:=1;
if kt=0 then writeln(st,' la xau doi xung')
else writeln(st,' khong la xau doi xung');
readln;
end.
Mng giúp mình các BT cuối kì vs ạ Bài 1: Viết chương trình nhập từ bàn phím 2 số nguyên a,b; Sau đó ghi chúng vào tệp có tên D:\Baitaptin.txt. Bài 2: Viết chương trình nhập từ bàn phím 1 xâu không quá 180 kí tự; Xuất xâu vừa nhập ra màn hình rồi ghi xâu đó vào tệp có tên E:\tepxau.txt. Bài 3: Viết chương trình nhập từ bàn phím 2 số nguyên dương; Tính và ghi tổng của chúng vào tệp có tên ‘teptong.txt’ rồi xuất tổng ra màn hình.
Bài 3:
uses crt;
const fi='teptong.txt'
var a,b:integer;
f1:text;
begin
clrscr;
assign(f1,fi); rewrite(f1);
readln(a,b);
writeln(a+b);
writeln(f1,a+b);
close(f1);
readln;
end.
Viết chương trình: - Nhập một xâu A (không quá 50 kí tự) bàn phím; - Tạo một xâu B chỉ chứa các kí tự là các chữ cái in hoa có trong xâu A và in xâu B ra màn hình;
uses crt;
var a,b:string;
i,d:integer;
begin
clrscr;
write('Nhap xau a:'); readln(a);
d:=length(a);
b:=''
for i:=1 to d do
if a[i] in ['A'..'Z'] then b:=b+a[i];
writeln(b);
readln;
end.
Viết chương trình nhập từ bàn phím một xâu kí tự st1 có độ dài tối đa là 60 1- Đếm số kí tự “A” và “a” trong xâu st1 2- Đưa ra màn hình xâu st2 gồm tất cả kí tự in thường trong xâu st1 3- Đưa ra màn hình xâu st1 là xâu in hoa Mng oiiiiiiiiiiiiiiiiiiiiiiii
Program HOC24;
var i,d1,d2: byte;
st1,st2: string[60];
begin
write('Nhap xau st1: '); readln(st1);
//---------------Câu 1-------------------
d1:=0; d2:=0;
for i:=1 to length(st1) do
begin
if st1[i]='A' then d1:=d1+1;
if st1[i]='a' then d2:=d2+1;
end;
writeln('Co ',d1,' ki tu A trong xau');
writeln('Co ',d2,' ki tu a trong xau');
//---------------------- Câu 2 --------------------
st2:=''
for i:=1 to length(st1) do if st1[i] in ['a'..'z'] then st2:=st2+st1[i];
writeln('Xau st2 la: ',st2);
//------------------------------Câu 3--------------------
for i:=1 to length(st1) do st1[i]:=upcase(st1[i]);
write('Xau st1 sau khi in hoa la: ',st1);
//--------------------------------------------------------
readln
end.
Viết chương trình nhập một xâu từ bàn phím .Đếm số lần xuất hiện của các kí tự trong xâu và in ra màn hình
uses crt;
var st:string;
a:array[1..255]of string;
i,d,dem,kt,j,dem1:integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
a[1]:=st[1];
dem:=1;
for i:=1 to d do
begin
kt:=0;
for j:=1 to dem do
if st[i]=a[j] then kt:=1;
if kt=0 then
begin
inc(dem);
a[dem]:=st[i];
end;
end;
for i:=1 to dem do
begin
dem1:=0;
for j:=1 to d do
if a[i]=st[j] then inc(dem1);
writeln(a[i],' xuat hien ',dem1,' lan');
end;
readln;
end.
uses crt;
var a:string;
c:char;
i,dem:integer;
begin
clrscr;
readln(a);
readln(c);
dem:=0;
for i:=1 to length(a) do
if a[i]=c then dem:=dem+1;
writeln(dem);
readln;
end.
Viết chương trình: Xâu A được nhập từ bàn phím . a) Viết xâu vừa nhập ra màn hình . b)tạo xâu B chứa các ký tự của xâu A
program NhapXau;
var
Chuoi_A, Chuoi_B : string;
i : integer;
begin
write('Nhap xau A: ');
readln(Chuoi_A);
writeln('Xau A la: ', Chuoi_A);
Chuoi_B := ''
for i := 1 to length(Chuoi_A) do
Chuoi_B := Chuoi_B + Chuoi_A[i];
writeln('Xau B la: ', Chuoi_B);
readln;
end.
viết chương trình nhập vào một xâu, thực hiện
1) in ra màn hình mỗi từ trên mỗi dòng
2) xóa các kí tự trống trong xâu
3) in hoa xâu vừa nhập
4) in xâu đảo ngược
Ai giải giúp em với ạ
Bài 3:
Program HOC24;
var s: string;
i: byte;
begin
write('Nhap xau : '); readln(s);
for i:=1 to length(s) do s[i]:=upcase(s[i]);
write('Xau sau khi in hoa : ',s);
readln
end.
Bài 4:
Program HOC24;
var s: string;
i: byte;
begin
write('Nhap xau : '); readln(s);
write('Xau sau khi dao nguoc: ');
for i:=length(s) downto 1 do write(s[i]);
readln
end.
Bài 1:
Program HOC24;
var s: string;
i: byte;
begin
write('Nhap xau : '); readln(s);
while s[1]=#32 do delete(s,1,1);
while pos(#32#32,s)<>0 do delete(s,pos(#32#32,s),1);
while s[length(s)]=#32 do delete(s,length(s),1);
for i:=1 to length(s) do
if s[i]=#32 then writeln(s[i]) else write(s[i]);
writeln;
readln
end.
Bài 2:
Program HOC24;
var s: string;
i: byte;
begin
write('Nhap xau : '); readln(s);
while s[1]=#32 do delete(s,1,1);
while pos(#32,s)<>0 do delete(s,pos(#32,s),1);
while s[length(s)]=#32 do delete(s,length(s),1);
writeln('Xau sau khi xoa ki tu trong: ',s);
readln
end.
Bài 4:
uses crt;
var st:string;
d,i:integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
for i:=d downto 1 do
write(st[i]);
readln;
end.