-
Notifications
You must be signed in to change notification settings - Fork 1
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
19-alstjr7437 #67
19-alstjr7437 #67
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.
์ ๋ ๋์ผํ ์์ด๋์ด๋ก ํ์์ต๋๋ค!
๋ ์ฐ๋ ํ์ด์ฌ์ด ์๋๋ผ ์ฒ์๋ณด๋ ์ธ์ด๋ผ์ ์ ๊ธฐํ๋ค์ ใทใท
import sys
inpur = sys.stdin.readline
N = int(input())
m = int(input())
lst = input().strip()
cur, ans, cnt = 0, 0, 0
while cur < m-1:
if lst[cur:cur+3] == 'IOI':
cnt += 1
cur += 2
if cnt == n:
ans += 1
cnt -= 1
else:
cnt = 0
cur += 1
print(ans)
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.
ํ๊ธด ํ์๋๋ฐ ๋จธ๋ฆฌ๊ฐ ์ด์ง๋ฝ๋ค์
import java.io.BufferedReader
import java.io.InputStreamReader
fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
val n = br.readLine().toInt()
val m = br.readLine().toInt()
val s = br.readLine()
var answer = 0
var i = 0
var count = 0
while (i < m - 2) {
if (s.substring(i, i + 3) == "IOI") {
i += 2
count++
if (count == n) {
answer++
count--
}
} else {
i++
count = 0
}
}
println(answer)
}
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.
์๊ฐ์ ์ผ๋ก ์๊ฐ๋์ง ์์ ํ์ด๋ฒ์ผ ๊ฑฐ ๊ฐ์์! ์ด๋ฐ ํจํด ๋ฌธ์ ๋๋ฌด ์ข์ํ๋๋ฐ ๊ฐ์ฌํฉ๋๋ค.
(์ค์ํํธ ๋ฌธ๋ฒ ์ ๊ธฐํ๋ค์)
import sys
input = sys.stdin.readline
N = int(input())
M = int(input())
S = input()
current_idx = 0
count = 0
result =0
while current_idx < M-2 :
if S[current_idx:current_idx+3] == 'IOI':
count+=1
current_idx+=2
if count == N :
count -=1
result +=1
else :
count=0
current_idx+=1
print(result)
๐ ๋ฌธ์ ๋งํฌ
IOIOI
โ๏ธ ์์๋ ์๊ฐ
45๋ถ
์ด๋ ๊ฒ ๊ฑธ๋ฆด ์๊ฐ์ด ์๋์๋๋ฐ Swift์ ๋ถ์กฑํ ๋ถ๋ถ์ ๋ง์ด ๋ฐ๊ฒฌํจ..
๊ทธ๋ฆฌ๊ณ 50์ ๋ถ๋ถ์์ ๋งํ์ ์์ด๋์ด๋ฅผ ๊ณ์ ์๊ฐํจ.
๐ ๋ฌธ์ ์ค๋ช
1๏ธโฃ 50์ ๋ง์ ์ฝ๋
์ ๋ ์ฒ์์๋ ๊ทธ๋ฅ ์๊ฐ๋ณต์ก๋๋ฅผ ์๊ฐํ์ง ์๊ณ ๊ฐ๋จํ๊ฒ ์๊ฐํ์ต๋๋ค.
์์ ๊ฐ์ด ์๊ฐํ๊ณ ์ฝ๋๋ฅผ ์ง๋ ์๋์ ๊ฐ์ด ๋์์ต๋๋ค
ํ์ง๋ง 50์ ์ ๋ง๊ธธ๋ ์ ์๊ฐ์ ํด๋ณด๋ ๊ทธ๋ ๊ฒ ๋๋ฉด ๋ชจ๋ s์ ๋ฌธ์์ด์ ์ธ๋ฑ์ค๋ก ๋ค ๋๋๊ฑฐ๋ผ ์๊ฐ์ด๊ณผ๊ฐ ๋๊ฒ ๋๋ผ๊ณ ์!
๐ฏ ์ฝ๋
๊ทธ๋์ ์๊ฐํ๊ณ ์ฐธ๊ณ ํ ๋ถ๋ถ์ด
์ ๋ฒํธ๋ฅผ ์๊ฐํ๋ฉด์ ๊ทธ๋ฆผ์ผ๋ก ์์ ๋ฅผ ํํํ๋ฉด
์์ ๊ฐ์ด ์๊ณ ๋ฆฌ์ฆ์ด ๋์๊ฐ์
result = 2๊ฐ ๋ฉ๋๋ค.
์์ ๊ฐ์ ์๊ณ ๋ฆฌ์ฆ์ ์งํํ๊ฒ ๋๋ฉด
IOI๊ฐ ๋์์๋ ํ์ฌ ์์น๋ฅผ 2์นธ ์์ผ๋ก ์ด๋ํ๊ธฐ ๋๋ฌธ์ ์๊ฐ์ด ์ค์ด๋๋ ๋ถ๋ถ์ ์๊ฐํ ์ ์์์ต๋๋ค.
์๋๋ IOI๊ฐ ๋์๋ ์ ์ฒด๋ก ๊ฐ์์ง ํ์ธ๋งํ๊ณ ๋ฐ๋ก ์ธ๋ฑ์ค๊ฐ +1๋ง ๋์ง๋ง ์ด๋ฌํ ๋ถ๋ถ์ผ๋ก ์งํํ๋ฉด ํ์คํ ์๊ฐ ๋ณต์ก๋๊ฐ ์ค์ด๋๋ ๋ถ๋ถ์ ํ์ธํ์์ต๋๋ค!
์ ์ฌ์ง์ ์์ ๋ก ์งํํ์๋ฅผ ์ดํด๋ณด๋ฉด
๐ป ์ต์ข ์ฝ๋
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
1๋ฒ ์์ด๋์ด๋ ์๋ ์ง๋๋ฐ ํ 7๋ถ์ด๋ฉด ๋๋ ์์ด๋์ด์์ง๋ง Swift์ธ์ด๋ก ์ง๋ณด๋ ๋๋ฐฐ๋ ๊ฑธ๋ฆฐ ๊ฒ ๊ฐ๋ค.
![image](https://private-user-images.githubusercontent.com/94051599/317315807-a57fab96-cd3f-41b5-9e56-599ddb440a8d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMDEzNTksIm5iZiI6MTczOTIwMTA1OSwicGF0aCI6Ii85NDA1MTU5OS8zMTczMTU4MDctYTU3ZmFiOTYtY2QzZi00MWI1LTllNTYtNTk5ZGRiNDQwYThkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDE1MjQxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNjYTUwYWZkYmY3YTE2MmUxNzMzZDllOTY5ZjI1OWVjOWI3ZmZhY2UyZGM1MTg3OGFjY2YzZWQwZTVhMTdjYWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.URvPKLAMtzk8C52fjGcdb62IlgksHQ9_3OuSLjTe9j0)
์ฌ๋ฌ๊ฐ์ง nil๋ก ์์๋ ์ฒ๋ฆฌ, ๋ฌธ์์ด์ ๋ฐ์์๋ map์ ์ด์ฉํ์ฌ ๋ฐฐ์ด๋ก ๋ง๋ค์ด์ผํจ(String์ Index ์ ๊ทผ์ด ์๋จ)
๊ทธ๋ฆฌ๊ณ ๋ค์ String๋ฐฐ์ด์ String์ผ๋ก ํ์ ๋ฐ๊ฟ์ค์ ๋น๊ต๋ฅผ ํ๋๊ฒ ๋๋ฌด ๊ท์ฐฎ์๋ค...
๊ทธ๋ฆฌ๊ณ ๋ฐฑ์ค ๊ธฐ๋ณธ์ธ์ด ๋ณ๊ฒฝ๋ ์์ง๋ง์..