a. Viết chương trình xoá các dấu cách thừa trong một xâu ký tự (giữa hai từ chỉ có một dấu cách )
B. Đổi các ký tự đầu từ của xâu sang chữ in hoa
C. Tách phần tên ra khỏi xâu gồm họ tên . Theo qui ước cách ghi tên của tiếng việt , tên là từ cuối cùng trong xâu.
Program HOC24;
var s: string;
i,x: byte;
begin
readln(s);
//-----------Câu a
while s[1]=#32 do delete(s,1,1);
while s[length(s)]=#32 do delete(s,length(s),1);
while pos(#32#32,s)<>0 do delete(s,pos(#32#32,1);
writeln(s);
//-------------Câu b
s[1]:=upcase(s[1]);
for i:=1 to length(s) do
if s[i]=#32 upcase(s[i+1]);
writeln(s);
//--------------Câu c
for i:=1 to length(s) do
if s[i]=#32 then x:=i;
for i:=x+1 to length(s) do
write(s[i]);
//---------------------------
readln
end.
viết chương trình nhập 1 xâu từ bàn phím. a) Hãy xóa tất cả các cách ký tự ở đầu xâu b) Hãy xóa tất cả các cách ký tự ở đầu xâu c) Hãy xóa tất cả các cách ký tự ở giữa các từ (giữa các từ chỉ có 1 dấu cách ) d) Đếm các chữ cái có trong xâu e) Đếm các chữ số ở xâu chuỗi. Trong màn hình kết quả
#include <bits/stdc++.h>
using namespace std;
int d,i,d1;
string st;
int main()
{
getline(cin,st);
d=st.length();
while (st[0]==32)
{
st.erase(0,1);
}
while (st[d-1]==32)
{
st.erase(d-1,1);
}
d1=st.length();
for (i=0; i<d1; i++)
if ((st[i]==32) && st[i+1]==32)
{
st.erase(i,1);
i--;
}
cout<<st;
return 0;
}
Viết chương trình nhập vào xâu ký tự S ,độ dài không quá 100 ký tự . Hãy chuẩn hóa xâu
-Xâu chuẩn là xâu không có dấu cách ở cuối câu , giữa 2 từ trong xâu chỉ có 1 dấu cách .
Uses crt;
Var st:string;
I,d:integer;
Begin
Clrscr;
Write('nhap xau:'); readln(st);
D:=length(st);
While st[d]=#32 do
Begin
Delete(st,d,1);
D:=length(st);
End;
For i:=1 to d do
If (st[i]=#32) and (st[i+1]=#32) then delete(st,i,1);
Writeln(st);
Readln;
End.
Viết chương trình nhập vào xâu ký tự S , độ dài không quá 100 ký tự . Hãy chuẩn hóa xâu
- Xâu chuẩn là xâu không có dấu cách ở đầu câu , giữa 2 từ trong xâu chỉ có 1 dấu cách .
Uses crt;
Var st:string;
I,d:integer;
Begin
Clrscr;
Write('nhap xau:'); readln(st);
D:=length(st);
While st[d]=#32 do
Begin
Delete(st,d,1);
D:=length(st);
End;
For i:=1 to d do
If (st[i]=#32) and (st[i+1]=#32) then delete(st,i,1);
Writeln(st);
Readln;
End.
Viết chương trình nhập vào từ bàn phím một xâu có thể chưa chuẩn về dấu cách, hãy loại bỏ các dấu cách thừa có trong xâu đó. Ví dụ : ' Hoc tap suot doi ''Hoc tap suot doi'
Cách làm:
+ Xóa dấu cách thừa ở đầu và cuối xâu: Kiểm tra cứ khi nào ký tự đầu tiên hoặc kí tự cuối của xâu S: là dấu cách thì xóa bỏ.
+Xóa dấu cách thừa ở giữa các từ: Cứ khi nào s[i] và s[i+1] đều là dấu cách thì xóa đi 1 dấu cách.
#include <bits/stdc++.h>
using namespace std;
int d,i,d1;
string st;
int main()
{
getline(cin,st);
d=st.length();
while (st[0]==32)
{
st.erase(0,1);
}
while (st[d-1]==32)
{
st.erase(d-1,1);
}
d1=st.length();
for (i=0; i<d1; i++)
if ((st[i]==32) && st[i+1]==32)
{
st.erase(i,1);
i--;
}
cout<<st;
return 0;
}
Nhập vào 1 xâu kí tự S từ bàn phím, rồi in ra xâu kí tự đó sau khi đã xoá hết các dấu cách thừa ở đầu, cuối xâu và giữa các từ trong xâu chỉ để lại 1 dấu cách BẰNG PYTHON Mọi người giúp em với ạ 😢😢😢
Viết chương trình nhập vào một xâu S có độ dài không quá 125 ký tự từ bàn phím. Xuất xâu đã nhập. Thực hiện xóa hết các dấu cách có trong xâu S. Xuất xâu S đã xóa các dấu cách ra màn hình
uses crt;
var st:string;
i,d:integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
writeln('Xau vua nhap la: ',st);
for i:=1 to d do
if st[i]=#32 then delete(st,i,1);
writeln('Xau moi la: ',st);
readln;
end.
Viết chương trình:
Nhập vào một xâu kí tự.
Đếm và in ra màn hình số kí tự là dấu cách có trong xâu.
Var a: string;
i, Dem: integer;
Begin
writeln(‘nhap xau:’);
Readln(a);
Dem:=0;
For i:=1 to length(a) do
If a[i] =’ ‘ then
Dem:= Dem+1;
Writeln(Dem);
Readln
End.
Hãy viết chương trình nhập vào từ bàn phím xâu kí tự S (không quá 200 kí tự). Sau đó thực hiện các công việc sau:
+ In lại xâu S theo chiều ngược lại.
+ Đếm xem trong xâu S có bao nhiêu từ.
VD: S= ‘Do Minh Thom87’
=> In lại xâu S: ’78mohT hniM oD’
=> Số từ: 3
Mọi người giúp mình với ạ!
Program HOC24;
var S: string;
d,i: byte;
begin
write('S= '); readln(s);
For i:= length(s) downto 1 do write(s[i]);
writeln;
while s[length(s)]=#32 do delete(s,length(s),1);
while pos(#32#32,s)<>0 do delete(s,pos(#32#32,s),1);
while s[1]=#32 do delete(s,1,1);
d:=0;
for i:=1 to length(s) do d:=d+1;
write('So tu :',d);
readln
end.
uses crt;
var s:string[200];
i,d,dem:integer;
begin
clrscr;
write('Nhap xau:'); readln(s);
d:=length(s);
write('Xau viet theo chieu nguoc la: ');
for i:=d downto 1 do
write(st[i]);
writeln;
dem:=0;
for i:=1 to d do
if st[i]=#32 then inc(dem);
writeln('So tu la: ',dem);
readln;
end.