
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
int main()
{
// =========================
// 1. 총알 3발 장전 후 첫 번째 총알 발사
// =========================
vector<string> bullets = { "총알", "총알", "총알" };
if (!bullets.empty())
{
bullets.erase(bullets.begin());
}
cout << "남은 총알 개수: " << bullets.size() << endl;
// =========================
// 2. 발사된 총알을 맨 뒤에 회수
// =========================
bullets.push_back("총알");
cout << "현재 총알 개수: " << bullets.size() << endl;
// =========================
// 3. 총알이 비었을 때 발사 시도
// =========================
bullets.clear();
if (bullets.empty())
{
cout << "총알 없음! 재장전 필요" << endl;
}
// =========================
// 4. 상점 장부 만들기
// =========================
map<string, int> shop;
shop["물약"] = 50;
shop["칼"] = 100;
// =========================
// 5. 물약 가격 찾기
// =========================
cout << "물약 가격: " << shop["물약"] << "원" << endl;
// =========================
// 6. 방패가 없으면 메시지 출력
// =========================
if (shop.find("방패") == shop.end())
{
cout << "판매하지 않는 물품입니다!" << endl;
}
// =========================
// 7. 인벤토리 사과 수량 누적
// =========================
map<string, int> inventory;
inventory["사과"] = 1;
inventory["사과"] += 1;
cout << "사과: " << inventory["사과"] << "개" << endl;
// =========================
// 8. 몬스터 처치 기록
// =========================
map<string, int> monsterKill;
monsterKill["슬라임"] = 3;
monsterKill["고블린"] = 1;
for (auto monster : monsterKill)
{
cout << monster.first << ": "
<< monster.second << "마리" << endl;
}
// =========================
// 9. 사과 사용 후 0개면 삭제
// =========================
inventory["사과"] -= 1;
cout << "남은 사과: "
<< inventory["사과"] << "개" << endl;
if (inventory["사과"] == 0)
{
inventory.erase("사과");
}
return 0;
}