-
Notifications
You must be signed in to change notification settings - Fork 1
7-caucsejunseo #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7-caucsejunseo #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฌธ์์ด ๊ทธ๋ฆฌ๋ ๋ฌธ์ ๋ค์!
์ ์ฒด ๋ฌธ์์์ XX 2๊ฐ๋ XXXX๋ก ๋ง๋ค ์ ์์ผ๋ XXXX๋ฅผ ์ฐ์ ์ ์ผ๋ก AAAA๋ก ๋ฐ๊ฟ ๋ฃ์ผ๋ฉด ๋๊ธฐ ๋๋ฌธ์
๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ์ด ๋ค์ด๊ฐ๋ ๊ฒ ๊ฐ๋ค์.
์ ๋ ๋น์ทํ ํ์ด์
๋๋ค.
string ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด์ ๊ฐ๋จํ๊ฒ ํ์ด๋ดค์ด์ฉ.
C++ ์ฝ๋
#include <iostream>
#include <string>
using namespace std;
int main() {
string board;
cin >> board;
//board์ XXXX๊ฐ ์์๋ ๋์๋ง
while(board.find("XXXX") != string::npos)
board.replace(board.find("XXXX"), 4, "AAAA");
while(board.find("XX") != string::npos)
board.replace(board.find("XX"), 2, "BB");
if(board.find('X') != string::npos) cout << -1;
else cout << board;
return 0;
}์๊ณ ๋ฆฌ๋๋ฏธ ๋๋ถ์ ํธ์ํ๋ ๋ฌธ์์ด ๋ฌธ์ ๋ฅผ ๋ง์ด ํ๊ฒ ๋๋ ๊ฒ ๊ฐ์ ์ข์ต๋๋ค.
|
์ ๋ ๋น์ทํ๊ฒ ํ์ด์ฌ์ผ๋ก ํ์ด๋ดค์ต๋๋ค. ๋ณด๋ํ์ ์ฐจ๋ก๋๋ก ํ์ํ๋ฉด์ X์ ๊ฐ์๋ฅผ ์ธ๊ณ , ๋๋์ ๊ณผ ๋๋จธ์ง ์ ๋ฆฌ๋ฅผ ํตํด ๋ต์ ๊ตฌํ์ต๋๋ค. ํ์ด์ฌ์ ํ์ด์ฌ ์ฝ๋
def solve(board):
result = []
i = 0
n = len(board)
while i < n:
if board[i] == 'X':
count = 0
while i < n and board[i] == 'X':
count += 1
i += 1
if count % 2 != 0:
return "-1"
result.append("AAAA" * (count // 4))
result.append("BB" * ((count % 4) // 2))
else:
result.append('.')
i += 1
return "".join(result)
board = input().rstrip()
print(solve(board)) |
hadongun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฐ๊ฐ์ด ๊ทธ๋ฆฌ๋ ๋ฌธ์ ๋ค์!
์ ๋ if๋ฌธ์ผ๋ก ํ๋ํ๋ ๊ฒฝ์ฐ๋ฅผ ๋๋์ด์ ํ์ด๋ณด์์ต๋๋ค
๋ฆฌ์คํธ ์์ ๋ฌธ์์ด์ ํ๋์ ๋ฌธ์์ด๋ก ํฉ์น๋ join์ ๋ํด์๋ ์๊ฒ ๋์์ด์!
ํ์ด๋ค
import sys
def popo():
board_temp = sys.stdin.readline().strip()
board = list(board_temp)
i = 0
while i < len(board):
if i + 3 < len(board) and board[i] == 'X' and board[i+1] == 'X' and board[i+2] == 'X' and board[i + 3] == 'X':
board[i] = 'A'
board[i + 1] = 'A'
board[i + 2] = 'A'
board[i + 3] = 'A'
i = i + 4
elif i + 1 < len(board) and board[i] == 'X' and board [i + 1] == 'X':
board[i] = 'B'
board[i + 1] = 'B'
i = i + 2
elif board[i] == '.':
i = i + 1
else:
print("-1")
return
onejum = ''.join(board)
print(onejum)
popo()
```python
</details>
###
๐ ๋ฌธ์ ๋งํฌ
ํด๋ฆฌ์ค๋ฏธ๋ ธ
โ๏ธ ์์๋ ์๊ฐ
45m
โจ ์๋ ์ฝ๋
^ํด๋ฆฌ์ค๋ฏธ๋ ธ
๋จธ๋ฆฌ๋ ์ํ ๊ฒธ ์ฌ์ด ๊ทธ๋ฆฌ๋ ๋ฌธ์ ํ์ด๋ดค์ต๋๋ค!
#8
์ด๋์ ์์ฃผ ์ ์ฌํ ๊ตฌ์กฐ์ ๋๋ค.
'.' ๋ ๋ ๋ฌธ์๊ฐ ๋์ค๊ธฐ ์ ๊น์ง ๋ฐ์ ๋ฌธ์์ด์ ๋ฐ๋ก ์ ์ฅํ๊ณ '.'์ด๋ ๋ ๋ฌธ์๊ฐ ๋์ค๋ฉด AAAA ๋ BB๋ฅผ ์ถ๋ ฅํ๋ฉด ๋ฉ๋๋ค!
๋ฌธ์ ๋ณด์๋ฉด ๋ฐ๋ก ์์๊ฒ ์ง๋ง 4๋ก ๋๋ ๋ชซ๊ณผ ๋๋จธ์ง๋ฅผ ๊ธฐ์ค์ผ๋ก ๋๋ ์ ์ถ๋ ฅํ๋ฉด ๋!
์๋์ฝ๋
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
memset->์ด๊ธฐํํ๋ ์ญํ !
๋ชฐ๋์ด์ div์ ๊ฐ์ ๋ชจ๋ 0์ผ๋ก ๋ฐ๊ฟ์ฃผ๋ ์์ผ๋ก ์ฒ์์ ์ ๊ทผํ๋๋ฐ ๊ทธ๋ ๊ฒ ํ๋ฉด ๋ฌธ์์ด ๊ฐ์๋ฅผ ์ฝ๋ strlen๋์ ๋ ผ๋ฆฌ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์์ด๋ค
strcat ๋ฌธ์์ด์ ๋ฐ๋ก ์ด์ด ๋ถ์ด๋ ํจ์