#34914: c++不用map解


ruoyuelouis@gmail.com (王若岳)

學校 : 不指定學校
編號 : 200090
來源 : [124.6.29.140]
最後登入時間 :
2025-06-01 17:13:14

不用二維,用兩個對應的陣列

#include <iostream>

using namespace std;

int main()
{
    int n, a=0;
    while(cin >> n && n!=0)
    {
        if(n==1)
        {
            int d[5]={4, 8, 7, 6, 3};
            string s[5]={"Medium Wac","WChicken Nugget","Geez Burger","ButtMilk Crispy Chicken","Plastic Toy"};
            int t;
            cin >> t;
            a+=d[t-1];
            cout << s[t-1] << " " << d[t-1] << endl;
        }
        else
        {
            int d[4]={2, 3, 5, 7};
            string s[4]={"German Fries","Durian Slices","WcFurry","Chocolate Sunday"};
            int t;
            cin >> t;
            a+=d[t-1];
            cout << s[t-1] << " " << d[t-1] << endl;
        }
    }
    cout << "Total: " << a << endl;

    return 0;
}