#include <iostream>
using namespace std;

class Car {
public:
    string name;
    int distance = 0;

    void move(int km) {
        distance += km;
    }
};

int main() {
    Car car[3];


    for (int i = 0; i < 3; i++) {
        cin >> car[i].name;
    }

    for (int i = 0; i < 3; i++) {
        int move;
        cin >> move;
    for (int j = 0; j < move; j++) {
        int km;
        cin >> km;
        car[i].move(km);
    }

    }

    for (int i = 0; i < 3; i++) {
        cout << "자동차 이름: " << car[i].name << endl;
        cout << "주행거리: " << car[i].distance << "km" << endl << endl;
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: