ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [C++] ์œ„์žฅ
    ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต 2019. 9. 20. 23:47
    728x90

    ๋ฌธ์ œ ์„ค๋ช…

    ์ŠคํŒŒ์ด๋“ค์€ ๋งค์ผ ๋‹ค๋ฅธ ์˜ท์„ ์กฐํ•ฉํ•˜์—ฌ ์ž…์–ด ์ž์‹ ์„ ์œ„์žฅํ•ฉ๋‹ˆ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด ์ŠคํŒŒ์ด๊ฐ€ ๊ฐ€์ง„ ์˜ท์ด ์•„๋ž˜์™€ ๊ฐ™๊ณ  ์˜ค๋Š˜ ์ŠคํŒŒ์ด๊ฐ€ ๋™๊ทธ๋ž€ ์•ˆ๊ฒฝ, ๊ธด ์ฝ”ํŠธ, ํŒŒ๋ž€์ƒ‰ ํ‹ฐ์…”์ธ ๋ฅผ ์ž…์—ˆ๋‹ค๋ฉด ๋‹ค์Œ๋‚ ์€ ์ฒญ๋ฐ”์ง€๋ฅผ ์ถ”๊ฐ€๋กœ ์ž…๊ฑฐ๋‚˜ ๋™๊ทธ๋ž€ ์•ˆ๊ฒฝ ๋Œ€์‹  ๊ฒ€์ • ์„ ๊ธ€๋ผ์Šค๋ฅผ ์ฐฉ์šฉํ•˜๊ฑฐ๋‚˜ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    ์ข…๋ฅ˜์ด๋ฆ„

    ์–ผ๊ตด ๋™๊ทธ๋ž€ ์•ˆ๊ฒฝ, ๊ฒ€์ • ์„ ๊ธ€๋ผ์Šค
    ์ƒ์˜ ํŒŒ๋ž€์ƒ‰ ํ‹ฐ์…”์ธ 
    ํ•˜์˜ ์ฒญ๋ฐ”์ง€
    ๊ฒ‰์˜ท ๊ธด ์ฝ”ํŠธ

    ์ŠคํŒŒ์ด๊ฐ€ ๊ฐ€์ง„ ์˜์ƒ๋“ค์ด ๋‹ด๊ธด 2์ฐจ์› ๋ฐฐ์—ด clothes๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ์„œ๋กœ ๋‹ค๋ฅธ ์˜ท์˜ ์กฐํ•ฉ์˜ ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

    ์ œํ•œ์‚ฌํ•ญ

    • clothes์˜ ๊ฐ ํ–‰์€ [์˜์ƒ์˜ ์ด๋ฆ„, ์˜์ƒ์˜ ์ข…๋ฅ˜]๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ์ŠคํŒŒ์ด๊ฐ€ ๊ฐ€์ง„ ์˜์ƒ์˜ ์ˆ˜๋Š” 1๊ฐœ ์ด์ƒ 30๊ฐœ ์ดํ•˜์ž…๋‹ˆ๋‹ค.
    • ๊ฐ™์€ ์ด๋ฆ„์„ ๊ฐ€์ง„ ์˜์ƒ์€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    • clothes์˜ ๋ชจ๋“  ์›์†Œ๋Š” ๋ฌธ์ž์—ด๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ๋ชจ๋“  ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ 20 ์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ด๊ณ  ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž ๋˜๋Š” '_' ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ์ŠคํŒŒ์ด๋Š” ํ•˜๋ฃจ์— ์ตœ์†Œ ํ•œ ๊ฐœ์˜ ์˜์ƒ์€ ์ž…์Šต๋‹ˆ๋‹ค.

    ์ž…์ถœ๋ ฅ ์˜ˆ

    clothes return
    [[yellow_hat, headgear], [blue_sunglasses, eyewear], [green_turban, headgear]] 5
    [[crow_mask, face], [blue_sunglasses, face], [smoky_makeup, face]] 3

    ์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

    ์˜ˆ์ œ #1
    headgear์— ํ•ด๋‹นํ•˜๋Š” ์˜์ƒ์ด yellowhat, greenturban์ด๊ณ  eyewear์— ํ•ด๋‹นํ•˜๋Š” ์˜์ƒ์ด blue_sunglasses์ด๋ฏ€๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด 5๊ฐœ์˜ ์กฐํ•ฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

    1. yellow_hat 2. blue_sunglasses 3. green_turban 4. yellow_hat + blue_sunglasses 5. green_turban + blue_sunglasses

    ์˜ˆ์ œ #2
    face์— ํ•ด๋‹นํ•˜๋Š” ์˜์ƒ์ด crowmask, bluesunglasses, smoky_makeup์ด๋ฏ€๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด 3๊ฐœ์˜ ์กฐํ•ฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

    1. crow_mask 2. blue_sunglasses 3. smoky_makeup

    #include <string>
    #include <vector>
    #include <algorithm>
    #include <map>
    #include <iostream>
    
    using namespace std;
    
    int solution(vector<vector<string>> clothes) {
    	int answer = 1;
    	map<string, int> spy;
    	string clothes_belong;
    
    	for (int i = 0; i < clothes.size(); i++)
    	{
    		clothes_belong = clothes[i][1];
    		spy[clothes_belong]++;
    	}
    
    	for (auto test : spy)
    	{
    		answer *= test.second + 1;
    	}
    
    	return answer - 1;
    }
    int main()
    {
    	vector<vector<string>> clothes;
    	int ans;
    
    	vector<string> tmp1;
    	tmp1.push_back("yellow_hat");
    	tmp1.push_back("headgear");
    	clothes.push_back(tmp1);
    
    	vector<string> tmp2;
    	tmp2.push_back("blue_sunglasses");
    	tmp2.push_back("eyewear");
    	clothes.push_back(tmp2);
    
    	vector<string> tmp3;
    	tmp3.push_back("green_turban");
    	tmp3.push_back("headgear");
    	clothes.push_back(tmp3);
    
    
    	ans = solution(clothes);
    
    	cout << ans << endl;
    
    }

    ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋ฒ•์„ ์•Œ์•„์•ผํ•˜๋Š” ๊ฒƒ์ด ์ œ์ผ ์ค‘์š”

    (n+1)(m+1)-1

    728x90

    ๋Œ“๊ธ€

Designed by Tistory.