Kodewick
学びはじめる →
ミニチャレンジ←→0 / 60

パン屋の注文

#057ミニチャレンジ約 6 分

パン屋さんが今日の注文票を出力します。breads と counts は対になっていて、パン i の注文数が counts[i] です。ループの中で、0 のものは飛ばし、それ以外は croissant x3 のような 1 行を表示して、数を total に足します。最後の行はもう書いてあります。

表示されるべき内容
croissant x3
baguette x2
muffin x5
total: 10
main.cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    vector<string> breads = {"croissant", "bagel", "baguette", "muffin"};
    vector<int> counts = {3, 0, 2, 5};
    int total = 0;
    for (int i = 0; i < (int)breads.size(); i++) {
        // ここにコードを書く:0 なら飛ばし、それ以外は 1 行表示して total に足す
    }
    cout << "total: " << total << endl;
    return 0;
}
Ctrl + Enter でも実行できます
結果

実行すると例で試せます。よさそうなら提出しましょう。