๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜

[C++/SWEA] 1215. [S/W ๋ฌธ์ œํ•ด๊ฒฐ ๊ธฐ๋ณธ] 3์ผ์ฐจ - ํšŒ๋ฌธ1 (D3)

728x90

 

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AV14QpAaAAwCFAYi&categoryId=AV14QpAaAAwCFAYi&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=CCPP&select-1=3&pageSize=10&pageIndex=2

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

ํšŒ๋ฌธ..

๋ฐ˜๋ณต๋ฌธ ์•ˆ์— ๋ณ€์ˆ˜ 2๊ฐœ ๋„ฃ๋Š”๊ฑฐ ์ฒ˜์Œ ํ•ด๋ด„ใ…‹ใ…‹ ์ด์ค‘๋ฐ˜๋ณต๋ฌธ๋ณด๋‹ค ๊น”๋”ํ•˜๊ธด ํ•˜๋‹ค

๊ฐ€๋กœ ๊ฐฏ์ˆ˜ ๊ตฌํ•˜๊ณ , ์„ธ๋กœ ๊ฐฏ์ˆ˜ ๊ตฌํ•ด์„œ ๋”ํ•˜๊ธฐ

 

๋‚˜์˜ ํ’€์ด

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(int argc, char** argv)
{
	int test_case;
	int len = 0;
    char c;
    //freopen("input.txt", "r", stdin);
    for (test_case = 1; test_case <= 10; ++test_case)
    {
        int answer = 0;
        vector<string> map;
        cin >> len;
        for (int i = 0; i < 8; ++i){
            string c;
            cin >> c;
            map.push_back(c);
        }
        for (int i = 0; i < 8; ++i){
            for (int j = 0; j <= 8 - len; ++j)
            {
                int s, e;
                for (s = j, e = j + len - 1; s <= e; ++s, --e)
                {
                    if (map[i][s] != map[i][e])
                        break;
                }
                if (s >= e)
                    answer++;
                
                for (s = j, e = j + len - 1; s <= e; ++s, --e)
                {
                    if(map[s][i] != map[e][i])
                        break;
                }
                if (s >= e)
                    answer++;
            }
        }

        cout << "#" << test_case << " " << answer << "\n";
    }
    return 0;
}
728x90