现给机器人穿鞋子、衬衫和裤子,其中鞋有运动鞋和皮鞋两双;衬衫有红色和白色两件;裤子有灰色和牛仔裤两条。但是必须符合以下规则:1运动鞋配牛仔裤,2皮鞋只能和灰裤子和白衬衫搭配,3白衬衫可以和牛仔裤搭配,4红衬衫只能和灰裤子搭配。给出机器人的具体穿衣搭配。用c++给出代码
时间: 2024-05-03 07:18:25 浏览: 201
以下是用 C++ 实现的代码:
```cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string shoe, shirt, pants;
cout << "Please choose a shoe (sneakers or leather): ";
cin >> shoe;
cout << "Please choose a shirt (red or white): ";
cin >> shirt;
cout << "Please choose a pants (grey or jeans): ";
cin >> pants;
if (shoe == "sneakers" && pants == "jeans") {
cout << "Robot is wearing sneakers, a " << shirt << " shirt, and jeans." << endl;
} else if (shoe == "leather" && pants == "grey" && shirt == "white") {
cout << "Robot is wearing leather shoes, a white shirt, and grey pants." << endl;
} else if (shoe == "leather" && pants == "grey" && shirt == "red") {
cout << "Invalid combination. Please choose white shirt instead." << endl;
} else if (shoe == "leather" && pants == "jeans") {
cout << "Invalid combination. Please choose grey pants instead." << endl;
} else if (shirt == "red" && pants == "grey") {
cout << "Robot is wearing " << shoe << ", a red shirt, and grey pants." << endl;
} else if (shirt == "white" && pants == "jeans") {
cout << "Robot is wearing " << shoe << ", a white shirt, and jeans." << endl;
} else {
cout << "Invalid combination. Please choose again." << endl;
}
return 0;
}
```
运行结果示例:
```
Please choose a shoe (sneakers or leather): sneakers
Please choose a shirt (red or white): white
Please choose a pants (grey or jeans): jeans
Robot is wearing sneakers, a white shirt, and jeans.
```
阅读全文