PASCAL從鍵盤輸入長度不超過40的字串,按要求進行刪除。求大師講解,給五十分

時間 2022-11-15 08:55:45

1樓:聽不清啊

var s:string; i,j,l:integer; c1,c2:char; found:boolean;

begin

readln(s); l:=length(s); found:=false;

read(c1);

if c1='d' then

begin

read(c2,c2);

i:=pos(c2,s);

if i>0 then begin delete(s,i,1); found:=true end;

end;

if c1='i' then

begin

read(c1,c1,c2,c2);

for i:=l downto 1 do

if s[i]=c1 then break;

if s[i]=c1 then begin insert(c2,s,i); found:=true end;

end;

if c1='r' then

begin

read(c1,c1,c2,c2);

for i:=1 to l do

if s[i]=c1 then begin s[i]:=c2; found:=true end;

end;

if found then writeln(s) else writeln('no this char.');

end.

2樓:匿名使用者

本題的關鍵是第二個輸入行的讀取和處理(解釋)。不像數字,read或readln在讀取字串時好像是整行讀取的,所以要將第二行先存入串變數中,然後將其按「空格」切分成多個部分......

從鍵盤輸入整數判斷它是否為素數,從鍵盤輸入乙個整數,判斷它是否為素數

演算法如下 已執行通過 include iostream.h include math.h define n 1000 bool fun int n void main 補充一下,求素數的方法還是有很多的,比如 1 遍歷2以上n的平方根以下的每乙個整數,是不是能整除n 這是最基本的方法 2 遍歷2以...

C語言問題,從鍵盤輸入n個英語單詞。輸入格式為n,w1,w2,w3 wn,其中n表示隨後輸入的英語

我提供個思路,你可以用遞迴的方式解這個問題。如果m 10,w1 1,則如果w1為滿足的若干件其中之一的話,則需要其他加起來為m w1,以此類推,直到w1到wn中有滿足的,且沒有重複的為止 include include include typedef struct link link void in...

c語言編寫程式提示從鍵盤輸入小於1000的正

蕪視壹苆灬 include stdio.h void aa int k 個位數字或者百位數字 void aaa int i,int j 特殊情況 void x int l 十位數字 void fun int a,int b,int c if b 1 aaa b,c if b 1 b 9 if b 0...

c 怎麼從鍵盤輸入隨機個字元用陣列

字元陣列的輸入輸出可以有兩種方法 1 逐個字元輸入輸出,如例5.9 2 將整個字串一次輸入或輸出 例如有以下程式段 char str 20 cin str 用字元陣列名輸入字串 cout 在執行時輸入乙個字串,如 china 在記憶體中,陣列str的狀態如圖5.9所示,在5個字元的後面自動加了乙個結...

C語言程式設計從鍵盤輸入班(全班最多不超過30人)學生某門課的成績,當輸入成績為負值時,輸入結束

先不說統計啥的,fun1 裡你的scanf d x i 沒有放到for迴圈裡。我忘了c裡面陣列申請時下標從1還是從0開始了,那麼只有x 3 有值,或者根本沒有x 3 記憶體溢位。你的 太凌亂了!看完就覺得沒幾句 是正確的,返回值不注意,變數的初始化也不注意,感覺跟沒學過c的一樣,要讓別人肯幫你修改,...