close
Content
題目:https://toi-reg.csie.ntnu.edu.tw/question/201903/B3-BigEater(Q).pdf
Wayne 是個饕客兼大胃王,而他最喜歡的食物就是麥噹噹的蘋果派和玉米濃湯,因此他決定要把口袋裡所有錢通通拿來吃 32 元的蘋果派和 55 元的大杯玉米濃湯。他最愛的吃法就是蘋果派與玉米濃湯交替著吃,也就是說若無法形成交替則不繼續進食,這是 Wayne 的堅持。請你幫忙寫程式列印出他大吃大喝的過程。
Input
輸入總共有三個整數,以空白隔開。第一個整數 N ( 0 ≤ N ≤ 500 )為 Wayne 總共帶了多少錢,第二個整數 M ( 0 < M ≤ 60 )為他每隔幾分鐘進食一次,第三個 整數 K = 0 的話代表從蘋果派開始吃,K = 1 的話則代表從玉米濃湯開始。
Output
每筆輸出包含經過時間、吃的食物與剩餘金額,請參考範例輸出。
Sample Input #1
65 5 0
Sample Output #1
0: Wayne eats an Apple pie, and now he has 33 dollars.
Sample Input #2
143 18 1
Sample Output #2
0: Wayne drinks a Corn soup, and now he has 88 dollars. 18: Wayne eats an Apple pie, and now he has 56 dollars. 36: Wayne drinks a Corn soup, and now he has 1 dollar.
Sample Input #3
55 1 1
Sample Output #3
0: Wayne drinks a Corn soup, and now he doesn't have money.
Sample Input #4
31 10 0
Sample Output #4
Wayne can't eat and drink.
測資資訊:
記憶體限制: 512 MB
公開 測資點#0 (5%): 1.0s , <1K
公開 測資點#1 (5%): 1.0s , <1K
公開 測資點#2 (5%): 1.0s , <1K
公開 測資點#3 (5%): 1.0s , <1K
公開 測資點#4 (5%): 1.0s , <1K
公開 測資點#5 (5%): 1.0s , <1K
公開 測資點#6 (5%): 1.0s , <1K
公開 測資點#7 (5%): 1.0s , <1K
公開 測資點#8 (5%): 1.0s , <1K
公開 測資點#9 (5%): 1.0s , <1K
公開 測資點#10 (5%): 1.0s , <1K
公開 測資點#11 (5%): 1.0s , <1K
公開 測資點#12 (5%): 1.0s , <1K
公開 測資點#13 (5%): 1.0s , <1K
公開 測資點#14 (5%): 1.0s , <1K
公開 測資點#15 (5%): 1.0s , <1K
公開 測資點#16 (5%): 1.0s , <1K
公開 測資點#17 (5%): 1.0s , <1K
公開 測資點#18 (5%): 1.0s , <1K
公開 測資點#19 (5%): 1.0s , <1K
公開 測資點#0 (5%): 1.0s , <1K
公開 測資點#1 (5%): 1.0s , <1K
公開 測資點#2 (5%): 1.0s , <1K
公開 測資點#3 (5%): 1.0s , <1K
公開 測資點#4 (5%): 1.0s , <1K
公開 測資點#5 (5%): 1.0s , <1K
公開 測資點#6 (5%): 1.0s , <1K
公開 測資點#7 (5%): 1.0s , <1K
公開 測資點#8 (5%): 1.0s , <1K
公開 測資點#9 (5%): 1.0s , <1K
公開 測資點#10 (5%): 1.0s , <1K
公開 測資點#11 (5%): 1.0s , <1K
公開 測資點#12 (5%): 1.0s , <1K
公開 測資點#13 (5%): 1.0s , <1K
公開 測資點#14 (5%): 1.0s , <1K
公開 測資點#15 (5%): 1.0s , <1K
公開 測資點#16 (5%): 1.0s , <1K
公開 測資點#17 (5%): 1.0s , <1K
公開 測資點#18 (5%): 1.0s , <1K
公開 測資點#19 (5%): 1.0s , <1K
#include <iostream> using namespace std; int main(){ int money,min,start; //n(??撠),m(撟曉??€脤?),k(0??瘣橘?1?掖瞈僖); int arr[2]={32,55}; int time=0; cin >>money >> min>>start; if(money<arr[start]){ cout << "Wayne can't eat and drink.\n"; return 0; } while (money>=arr[start]) { cout<<time<<": Wayne "; if(start==0){ cout<<"eats an Apple pie, "; } else{ cout<<"drinks a Corn soup, "; } money-=arr[start]; if(money==0){ cout<<"and now he doesn't have money.\n"; } else{ if(money==1){ cout<<"and now he has "<<money<<" dollar.\n"; } else{ cout<<"and now he has "<<money<<" dollars.\n"; } } start=1-start; time+=min; } }
文章標籤
全站熱搜
留言列表