Tajriba mashg’uloti № 20
Paskal tilida simvol va satrlar bilan ishlash
Mashg’ulotning maqsadi: talabalarda simvollar va satrlar bilan ishlash malaka va ko‘nikmalarini hosil qilish.
Nazariy ma’lumotlar ma’ruza darslarida keltirilgan.
28– masala uchun programma
|
Borland delphi tilida
|
Borland C++ tilida
|
program string28;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
f1,f2:text;
s,s1:string;
c:char;k:word;i:byte;
begin
assign(f1,'string28.in');reset(f1);
assign(f2,'string28.out');rewrite(f2);
readln(f1,s);
readln(f1,c);
s1:=' ';
k:=length(s);
for i:=1 to k do
begin
if (s[i]=c) then s1:=s1+s[i];
s1:=s1+s[i];
end;
write(f2,s1);
close(f1);
close(f2);
end.
|
#pragma string28
#include
#include
int main(int argc, char **argv)
{
static char s[64],s1[64],*ss[64],c;
static short int k,i,j;
ifstream f1("string28.in");
ofstream f2("string28.out");
f1.getline(s,sizeof(s));
*ss=s;
k=strlen(*ss);
f1>>c;
j=0;
for (i=0;i{
if (s[i]==c) {s1[j]=s[i];j++;};
s1[j]=s[i];j++;
}
for (i=0;i
f2<
f1.close();
f2.close();
return 0;
}
|
66– masala uchun programma
|
program string66;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
f1,f2:text;
s,s1,s2:string;
k:word;i:byte;
begin
assign(f1,'string66.in');reset(f1);
assign(f2,'string66.out');rewrite(f2);
readln(f1,s);
k:=length(s);
s1:=' ';s2:=' ';
for i:=1 to k do
if (i mod 2<>0) then s2:=s2+s[i]
else s1:=s1+s[i];
k:=length(s2);
for i:=k downto 1 do
s1:=s1+s2[i];
write(f2,s1);
close(f1);
close(f2);
end.
|
#pragma string66
#include
int main(int argc, char **argv)
{
static char s[64],s1[64],s2[64],*ss[64];
static short int k,i,j,l;
ifstream f1("string66.in");
ofstream f2("string66.out");
f1.getline(s,sizeof(s));
*ss=s;
k=strlen(*ss);
s1[0]=' ';s2[0]=' ';j=0;l=0;
for (i=0;i
if (i % 2!=0) {s2[j]=s[i];j++;}
else { s1[l]=s[i];l++;}
for (i=l-1;i>=0;i--)
{s2[j-1]=s1[i];j++;}
for (i=0;i
f2<
f1.close();
f2.close();
return 0;
}
|
Topshiriqlar:
1. Simvollar va ularning kodlari. Satrlar tashkil etish
1. c simvoli berilgan. Uning kodi chop etilsin.
2. n(32≤n≤126) butun soni berilgan. Kodi n ga teng bo‘lgan simvol chop etilsin.
3. c simvoli berilgan. c simvoldan (jadvalda) oldin va keyin joylashgan 2 ta simvol chop etilsin.
4. n (1≤n≤26) soni berilgan. Lotin alfavitidagi birinchi n ta bosh hartflar chop etilsin.
5. n (1≤n≤26) soni berilgan. Lotin alfavitidagi oxirgi n ta kichik hartflar chop etilsin.
6. Raham yoki harfni aks ettiruvchi c simvol berilgan. Agar c raham bo‘lsa, “raham”, lotin harfi bo‘lsa “lat”, krill harfi bo‘lsa “rus” satri chop etilsin.
7. Bo‘sh bo‘lmagan satr berilgan. Uning birinchi va oxirgi simvollarining kodlari chop etilsin.
8. n(n>0) butun son va c simvol berilgan. c simvoldan tuzilgan n uzunlikka ega satr chiqarilsin.
9. n(n>0) juft soni va c1, c2, simvollar berilgan. c1 dan boshlab navbat bilan almashib keluvchi n uzunlikka ega c1 va c2 dan tuzilgan ketma-ketlik chop etilsin.
10. Satr berilgan. Uni joylashish o‘rniga nisbatan teskari tartibda chop etilsin.
11. Bo‘sh bo‘lmagan s satr berilgan. s satrda joylashgan simvollarning orasiga bittadan bo‘sh joy qo‘yib chop etilsin.
12. Bo‘sh bo‘lmagan s satr va n(n>0) butun soni berilgan. s satrdagi simvollar orasiga n tadan “*” qo`yib chop etilsin.
Do'stlaringiz bilan baham: |