Problem:
์ํธ ๊ด๋ฆฌ ์์ฉํ๋ก๊ทธ๋จ์ map์ ์ด์ฉํ์ฌ ์์ฑํ๋ผ.
์คํ ๊ณผ์ ์ ๋ค์๊ณผ ๊ฐ๋ค.
Execution Result:
Objective & Hints:
map ์ปจํ
์ด๋์ ์ฝ์
๋ฐ ์กฐํ ์์ฉ
์ด๋ฆ๊ณผ ์ ์๋ฅผ ์์ผ๋ก ์ ์ฅํ ๋งต ์ปจํ
์ด๋๋ก map<string, string>์ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
์๋ ๋งํฌ์ ์๋ Exercise Problem 10์ฅ 13๋ฒ์ ์ฐธ๊ณ ํ์ธ์.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #include #include using namespace std; void insert(map<string, string> &pwManager){ string name, pw; cout << "์ด๋ฆ ์ํธ>> "; cin >> name >> pw; pwManager.insert(make_pair(name, pw)); } void checkNamePw(map<string, string> &pwManager){ string name, pw; cout << "์ด๋ฆ? "; cin >> name; while(true){ cout << "์ํธ? "; cin >> pw; if(pwManager[name] == pw){ cout << "ํต๊ณผ!!\n"; break; } else cout << "์คํจ~~\n"; // ํ๋ฆฌ๋ฉด ์ถ๋ ฅ ํ ๋ค์ ์ํธ ์ง๋ฌธ } } int main() { map<string, string> pwManager; cout << "***** ์ํธ ๊ด๋ฆฌ ํ๋ก๊ทธ๋จ WHO๋ฅผ ์์ํฉ๋๋ค *****\n"; while(true){ cout << "์ฝ์
:1, ๊ฒ์ฌ:2, ์ข
๋ฃ3>> "; int n; cin >> n; switch(n){ case 1: insert(pwManager); break; case 2: checkNamePw(pwManager); break; case 3: cout << "ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํฉ๋๋ค..."; return 0; } } } Explanation:
...