C언어/문제풀다 하나씩
오랜만에 direct배열 써보기
mcdn
2020. 5. 22. 10:59
반응형
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string abc[3] = {
"ABCEFG",
"HIJKLM",
"NOPQRS"
};
string result[3] = {
"ABCEFG",
"HIJKLM",
"NOPQRS"
};
string inputabc;
int direct[5][2] = {
{0,-1}, {0,1}, {1,0}, {-1,0}, {0,0}
};
void flip(char a) {
int ay, ax;
for (int i = 0; i < 3;i++) {
for (int j = 0; j < 6;j++) {
if (a == abc[i][j]) {
ay = i;
ax = j;
}
}
}
for (int i = 0; i < 5;i++) {
int dy, dx;
dy = ay + direct[i][0];
dx = ax + direct[i][1];
if (dy >= 0 && dy < 3 && dx >= 0 && dx < 6) {
if (result[dy][dx] == '#') {
result[dy][dx] = abc[dy][dx];
}
else {
result[dy][dx] = '#';
}
}
}
}
int main() {
cin >> inputabc;
int len = inputabc.length();
for (int i = 0; i < len;i++) {
flip(inputabc[i]);
}
for (int i = 0; i < 3;i++) {
cout << result[i] << endl;
}
}
입력 예제
BE
출력 결과
##C##G H#J#LM NOPQRS
반응형