#12571: C++ 簡易參考解答


shawn2000100 (東華財金)

學校 : 國立東華大學
編號 : 57300
來源 : [27.53.168.5]
最後登入時間 :
2021-09-19 19:53:19
d710. parking lot -- 葆葆 | From: [124.9.162.248] | 發表日期 : 2017-08-13 22:22

#include <iostream>
#include <string>
using namespace std;

class Car {
public:
void setting ( string bra, string col );
string getBrand ( void );
string getColor ( void );
private:
string brand;
string color;
};

void Car::setting ( string bra, string col ) {
this->brand = bra;
this->color = col;
}

inline string Car::getBrand() {
return brand;
}

inline string Car::getColor() {
return color;
}

int main() {
int n, m;
string bra, col, cmd;
Car parkingLotA[21];
while ( cin >> n >> m ) {
for ( int i = 0; i < n; ++i ) {
cin >> bra >> col;
parkingLotA[i].setting ( bra, col );
}
for ( int j = 0; j < m; ++j ) {
cin >> cmd;
if ( cmd == "brand" ) {
cin >> bra;
for ( int i = 0; i < n; ++i )
if ( parkingLotA[i].getBrand() == bra )
cout << parkingLotA[i].getBrand() << " " << parkingLotA[i].getColor() << endl;
} else {
cin >> col;
for ( int i = 0; i < n; ++i )
if ( parkingLotA[i].getColor() == col )
cout << parkingLotA[i].getBrand() << " " << parkingLotA[i].getColor() << endl;
}
}
}
return 0;
}

 
ZeroJudge Forum