Viết chương trình nhập vào 1 xâu, hãy cho biết tổng của các số trong xâu. (Pascal ) VD: abc1eg22kh123
= 1+22+123=146
CíuuuuuT_T
Viết chương trình nhập vào 1 xâu, hãy ĐẾM số kí tự số trong xâu. (Pascal )
VD: Nhập s: 123yuo@hg5
In ra:4
Program hotrotinhoc;
var s: string;
t,c,i: byte;
begin
write('Nhap s:'); readln(s);
t:=0;
for i:=1 to length(s) do
if s[i] in ['1'..'9'] then
begin
val(s[i],c);
t:=t+c;
end;
write(t);
readln
end.
Thu gọn
1. Cho xâu S nhập từ bàn phím. Viết chương trình xóa các kí tự dư thừa trong xâu và biến các kí tự trong xâu thành chữ hoa.
2. Cho xâu s nhập từ bàn phím.Định dạng xâu theo kiểu tên người VD Truong Vinh Ky
1 Viết chương trình nhập mạng một chiều n tính và in ra màn hình tổng số lẻ 2 viết chương trình nhập vào một xâu từ văn phím viết chương trình chuẩn hóa xâu bằng cách xóa các ký tự trống ở đâu xâu và cuối xâu 3 Viết các thao tác và lần tương ứng cần thực hiện để đọc một giá trị từ tệp ‘ DL.TXT ‘ Ghi giá trị vừa đọc vào tệp ‘KQ.TXT’ Giúp mình với ạ
1:
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t+a[i];
writeln(t);
readln;
end.
3:
const fi='dl.txt'
fo='kq.txt'
var f1,f2:text;
a:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,a);
writeln(f2,a);
close(f1);
close(f2);
end.
2:
uses crt;
var st:string;
d:integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
while st[1]=#32 do
begin
delete(st,1,1);
d:=length(st);
end;
while st[d]=#32 do
begin
delete(st,d,1);
d:=length(st);
end;
writeln(st);
readln;
end.
Viết chương trình nhập vào 1 xâu. In từ sau cùng của xâu ra màn hình VD: Nguyen Van An => An
Uses crt;
Var i:integer;
s1,s2:string;
Begin
clrscr;
Writeln('Nhap xau:');readln(s1);
s2:=''
i:=length(s1);
While s1[i]<> ' ' do
Begin
s2:=s2+s1[i];
i:=i-1;
End;
Writeln('Tu sau cung cua xau la:');
For i:=length(s2) downto 1 do write(s2[i]);
readln;
End.
uses crt;
var st,s:string;
i,d:integer;
begin
clrscr;
readln(st);
d:=length(st);
s:=''
i:=d;
while st[i]<>#32 do
begin
s:=s+st[i];
i:=i-1;
end;
for i:=length(s) downto 1 do
write(s[i]);
readln;
end.
1. Viết chương trình nhập vào một số nguyên dương n. Hãy in ra số nguyên tố nhỏ nhất lớn hơn n. 2. Viết chương trình nhập vào một xâu. In ra màn hình số lớn nhất trong xâu đó.
câu 1
Program Nguyen_to;
Var n,i:integer;
Function NT(n:integer):Boolean;
Var ok: Boolean;
i: integer;
Begin ok:=true;
for i:=2 to n-1 do if (n mod i)= 0 then ok:=ok and false;
if n < 2 then NT:=false else NT:=ok;
End;
Begin Write('Nhap n: ');
Readln(n); i:=n;
Repeat i:=i+1;
Until NT(i);
Write('So nguyen to nho nhat lon hon ',n, 'la: ',i);
Readln End.
câu 2
uses crt;
const so: set of char=['0','1','2','3','4','5','6','7','8','9'];
var a:array[1..100] of integer;
st,b:string;
c,l,i,n,j:integer;
s, Max: integer;
begin clrscr;
write('Nhap xau:');
readln(st);
l:=length(st);
i:=1;
n:=0;
repeat if (st[i] in so) then begin b:=''
repeat b:=b+st[i];
inc(i);
until (not(st[i] in so)) or (i>l);
inc(n);
val(b,a[n],c);
end;
inc(i);
until i>l;
Max:=a[1];
for i:=2 to n do If Max<A[i] Then Max:=A[i];
Writeln('Phan tu lon nhat cua mang:', Max);
readln;
end.
a. Viết chương trình nhập vào 1 xâu bất kì xuất ra độ dài cùa xâu và số kí tự trống.
b. Viết chương trình nhập vào một xâu bất kì xuất ra xâu đảo ngược
c.Viết chương trình nhập vào một xâu bất kì xuất ra xâu có là xâu đối xứng hay không đối xứng
d. Viết chương trình nhập vào một xâu bất kì xuất ra xâu viết in hoa tất cả
Hãy viết chương trình nhập vào 1 xâu kí tự là Hoten của em rồi hãy tạo ra 1 xâu mới được CHÈN từ Họ trong xâu Họ tên vừa nhập. In ra xâu kết quả
CÁC BẠN GIÚP MÌNH SẮP THI RỒIIII
viết chương trình pascal Hoán vị ký tự theo khóa - Tên chương trình GRCAE.???
Nhập vào xâu S chỉ chứa các ký tự là chỉ cái in thường và khoảng trắng.
Cho trước khóa m là một hoán vị của n số (2<n<18). Để mã hóa một xâu ký tự ta có thể chia xâu thành từng nhóm từ trái sang phải mỗi nhóm có n ký tự; nếu nhóm cuối không đủ n ký tự thì ta có thể thêm các ký tự trắng vào sau cho đủ. Sau đó hoán vị các ký tự trong từng nhóm theo khóa, ghép các nhóm xâu lại theo thứ tự ta được một xâu đã mã hóa. Hãy viết chương trình mã hóa một xâu kí tự cho trước.
Ví dụ: Với n=8 và khóa m=87345621, thực mã hóa xâu S = “hello every body” như sau:
Tách xâu S thành các xâu mỗi xâu có 8 ký tự:
S1 = “hello ev”; S2 = “ery o body”
Thực hiện mã hóa xâu S1, S2 theo khóa m ta được S1’ và S2’:
S1’ = “vello eh”; S2’ =”ydy bore”
Input: GRCAE.INP
· Dòng 1: số nguyên n (2<n<18) và m (m là số nguyên có n chữ số).
· Dòng 2: ghi xâu cần mã hóa (độ dài xâu <=10^5).
Ouput: GRCAE.OUT
· Mỗi dòng ghi 1 xâu có n ký tự đã được mã hóa.
Ví dụ:
GRCAE.INP GRCAE.OUT
8 87345621
hello every body vello eh ydy bore
1.Hãy viết chương trình nhập vào 1 xâu kí tự là Hoten của em rồi hãy tạo ra 1 xâu mới được COPY từ Họ trong xâu Họ tên vừa nhập. In ra xâu kết quả
CÁC BẠN GIÚP MÌNH MÌNH SẮP THI RỒI I!!!