#29359: C語言寫法


krameri120 (科科)

學校 : 國立臺南高級工業職業學校
編號 : 102318
來源 : [118.231.192.42]
最後登入時間 :
2024-05-17 17:57:08
f046. 公車上的跑馬燈 -- 板橋高中Python教學題 | From: [39.9.37.232] | 發表日期 : 2022-02-17 21:22

你可以利用scanf("%[^\n]%*c",main);整行讀入

scanf("%d%*c",&width);

scanf("%[^\n]%*c",main);

scanf("%d",&time);

這樣三筆資料都會存入

第一行"%d%*c的%*c是為了刷掉stdin中的\n

迴圈可以用for(int x=time-width,count=0;x<=time;x++,count++){

再把資料存入 reverse[count]=main[x];

}

記得迴圈中要加條件if(x<0)
直接把設為reverse[count]=' '然後continue;

完整code丟在github,歡迎參考~

https://github.com/kerong2002/kerong_zerojudge/blob/main/f046%20%E5%85%AC%E8%BB%8A%E4%B8%8A%E7%9A%84%E8%B7%91%E9%A6%AC%E7%87%88.c

 

 
ZeroJudge Forum