[#96][알고리즘][SW Expert Academy] 3143. 가장 빠른 문자열 타이핑
[SW Expert Academy] 3143. 가장 빠른 문자열 타이핑
문제 링크 (https://swexpertacademy.com/main/code/problem/problemSolver.do?contestProbId=AV_65wkqsb4DFAWS)C++풀이
| 
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 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 | 
#include <iostream> 
#include <vector> 
#include <algorithm> 
using namespace std; 
vector<int> vct; 
bool check[101][101] = { false }, visited[101][101] = { false }; 
int M, N, K, arr[101][101], countAnswer = 0; 
int tx[4] = { 1,0,-1,0 }; 
int ty[4] = { 0,-1,0,1 }; 
//블록을 제외한 영역  
void dfs(int x, int y) { 
    for (int i = 0; i < 4; i++) { 
        int nx = x + tx[i]; 
        int ny = y + ty[i]; 
        if (nx >= 0 && nx < M && ny >= 0 && ny < N && !visited[nx][ny] && !check[nx][ny]) { 
            visited[nx][ny] = true; 
            countAnswer++; 
            dfs(nx, ny); 
        } 
    } 
} 
int main() { 
    cin >> M >> N >> K; 
    for (int i = 0; i < K; i++) { 
        for (int j = 0; j < 4; j++) { 
            cin >> arr[i][j]; 
        } 
    } 
    for (int i = 0; i < K; i++) { 
        int x = abs(arr[i][2] - arr[i][0]); 
        int y = abs(arr[i][3] - arr[i][1]); 
        check[arr[i][1]][arr[i][0]] = true; 
        for (int j = 0; j < x; j++) { 
            for (int k = 0; k < y; k++) { 
                check[arr[i][1] + k][arr[i][0] + j] = true; 
            } 
        } 
    } 
    for (int i = 0; i < M; i++) { 
        for (int j = 0; j < N; j++) { 
            if (!check[i][j] && !visited[i][j]) { 
                visited[i][j] = true; 
                countAnswer = 1; 
                dfs(i, j); 
                vct.push_back(countAnswer); 
            } 
        } 
    } 
    //오름차순 정렬하여 출력 
    sort(vct.begin(), vct.end()); 
    cout << vct.size() << endl; 
    for (int j = 0; j < vct.size(); j++) { 
        cout << vct[j] << " "; 
    } 
    return 0; 
} | cs | 
| 
#include <iostream> 
#include <string> 
using namespace std; 
int main() { 
    int testCase; 
    cin >> testCase; 
    for (int i = 1; i <= testCase; i++) { 
        string input, str; 
        cin >> input >> str; 
        //문자열에 특정 문자열이 있는지 확인 
        while (input.find(str) != string::npos) { 
            int k = 0; 
            //특정 문자열이 시작되는 위치 
            k = input.find(str); 
            //그 위치부터 str 길이만큼 삭제  
            input.erase(k, str.length()); 
            //대신 문자 1개 삽입. (1개의 키로 줄인것) 
            input.insert(k, "*"); 
        } 
        cout << "#" << i << " " << input.length() << endl; 
    } 
    return 0; 
} | cs | 

댓글
댓글 쓰기