반응형

문제 출처 :


https://www.acmicpc.net/problem/3023



알고리즘 분석 :


문제 해결에 필요한 사항

1. 구현


이 문제는 입력부 부터 y축에 대해 대칭한 값을 reverse를 통해 구하고, 그 값을 str[i]에 추가해준다.


그런 후 x축에 대해 대칭을 해준 값을 str[nn]을 통해 넣어주면 하나의 카드가 만들어진다.


마지막으로 y,x를 입력받고 #이면 .으로 .이면 #으로 바꾸면 정답을 도출 할 수 있다.






소스 코드 : 


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
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
 
using namespace std;
 
string str[105];
 
int main()
{
    int n, m;
    scanf("%d %d"&n, &m);
 
    int nn = n * - 1;
    for (int i = 0; i < n; i++)
    {
        cin >> str[i];
 
        string tmp = str[i];
        reverse(tmp.begin(), tmp.end());
 
        str[i] += tmp;
 
        str[nn] = str[i];
        nn--;
    }
 
    int y, x;
    scanf("%d %d"&y, &x);
 
    y--, x--;
    if(str[y][x] == '#')
    {
        str[y].erase(str[y].begin() + x, str[y].begin() + x + 1);
        str[y].insert(str[y].begin() + x, '.');
    }
    else
    {
        str[y].erase(str[y].begin() + x, str[y].begin() + x +);
        str[y].insert(str[y].begin() + x, '#');
    }
 
    for (int i = 0; i < * n; i++)
        cout << str[i] << endl;
        
 
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형