-
Notifications
You must be signed in to change notification settings - Fork 0
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-suhyun113 #31
7-suhyun113 #31
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.
์ ๊ฐ ํธ๋ฆฌ์ ์ฝํ ๊ฑด์ง... ๋ฌธ์ ๋ฅผ ์ฝ๊ณ ๋ ์ฝ์ด๋ ์ดํด๊ฐ ์ ๊ฐ์ ์ฐธ๊ณ ํ ๋ธ๋ก๊ทธ ์ ๋ ํ๋ ์ด์ ์ผ ์ดํด๊ฐ ๊ฐ๋๋ผ๊ตฌ์... ๊ทธ๋์ ๋ฆฌ๋ทฐ๊ฐ ๋ฆ์์ต๋๋ค ใ ใ
์ด ๋ฌธ์ ๋ ๊ฒฐ๊ตญ ํธ๋ฆฌ์ ๊น์ด๋ฅผ ๊ตฌํ๊ธฐ๋ง ํ๋ฉด ๋๋ ๋ฌธ์ ๋๋ผ๊ณ ์!
ํ์ฌ ๊น์ด๋ฅผ ์ธก์ ํ๋ ๋ณ์
๋ฅผ ํ๋ ๋๊ณ , ์ฃผ์ด์ง ๊ดํธ ๋ฌธ์์ด์์ ์ฌ๋ ๊ดํธ [
๊ฐ ๋์ค๋ฉด ์ฆ๊ฐ, ๋ซ๋ ๊ดํธ ]
๊ฐ ๋์ค๋ฉด ๊ฐ์์ํค๋ฉด์ ๊ทธ์ค ๋ฑ์ฅํ๋ ์ ์ผ ํฐ ๊ฐ์ด ๊น์ด๊ฐ ๋๋๋ก ํ๋!! ์ํ๋์ด๋ ํ์ด ๋ฐฉ์์ด ๊ฐ๋ค์ ใ
ใ
ํธ๋ฆฌ.. ์ฝ์ง ์๋ค์... pr ์๊ณ ํ์ จ์ด์!
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.
์ ๋ ๋ฌธ์ ๊ฐ ์ดํด๊ฐ ๋ฐ๋ก ๋์ง์์ ์๊ฐ์ ๋ง์ดํ๋ค๊ฐ ํ๊ฒ ๋์๋ค์.
๊ฒฐ๋ก ์ ์ผ๋ก๋ ๋ฌธ์์ด์ ํธ๋ฆฌ๋ก ๋ดค์ ๋ ๊ทธ ๊น์ด๋ฅผ ๊ตฌํ๋ ๋ฌธ์ ์๋ค์. ๊ฐ๋
๋ฌธ์ ์๋๋ฐ ์ ๋ ๋ํ๋์ฒ๋ผ ๋ญ๊ฐ ์ ํ๋ฆฌ์ง ์์์ด์..
์ ๋ c++๋ก ๊ฑฐ์ ๋๊ฐ์ ๋ก์ง์ผ๋ก ํ์ด๋ดค๋๋ฐ์.
๋งํ ๋ถ๋ถ์ด cin์ ์ค๋ฐ๊ฟ ๋ฌธ์ ํ๋๋ ์
๋ ฅ์ผ๋ก ๋ฐ์ง ๋ชปํ๋๋ผ๊ตฌ์. ๊ทธ๋์ getline์ ์จ๋ดค๋๋ ํด๊ฒฐ๋์์ต๋๋ค. ๋ฆฌ๋ทฐ๋ฌ๋ค๊ฐ cin ์ฒ๋ฆฌ ๋ฐฉ์์ ๋ํด์ ํ๋ฒ ๋ ๋ณต์ตํ๊ณ ๊ฐ๋๋ค.
์ ๋ ๋ค์ ๋ฌธ์ ํธ๋ฆฌ๋ก ๊ฐ์ง๊ณ ์๋ณด๊ฒ ์ต๋๋ค๐ ์ด๋ฒ PR๋ ์๊ณ ํ์
จ์ต๋๋ค๐
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
cin.ignore();
while (n--) {
string input;
getline(cin, input);
int depth = 0, maxDepth = 0;
for (const auto &c : input) {
if (c == '[') {
depth++;
maxDepth = max(depth, maxDepth);
}
else if (c == ']') {
depth--;
}
}
int result = 1;
while(maxDepth--){
result *= 2;
}
cout << result << "\n";
}
return 0;
}
๐ ๋ฌธ์ ๋งํฌ
https://www.acmicpc.net/problem/2716
โ๏ธ ์์๋ ์๊ฐ
์ฝ 40๋ถ
โจ ์๋ ์ฝ๋
๐ฉต1. ํ์ด ๋ฐฉํฅ ์๊ฐํ๊ธฐ!๐ฉต
=> ๋ฉ๊ตด์ ๊ท ํ ์ ์งํ๋ฉฐ ๋๋ฌด ๊ผญ๋๊ธฐ์ ๋๋ฌํ ์ ์๋ ์ต์ ์์ญ์ด ์?
๐ฉต2. ์์๐ฉต
![image](https://private-user-images.githubusercontent.com/163711629/344519239-4c1babf8-42b9-4677-84f4-8b5928164351.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMDAzOTgsIm5iZiI6MTczOTIwMDA5OCwicGF0aCI6Ii8xNjM3MTE2MjkvMzQ0NTE5MjM5LTRjMWJhYmY4LTQyYjktNDY3Ny04NGY0LThiNTkyODE2NDM1MS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMFQxNTA4MThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05NjY0NzhjMjlmMWI0YjQ2NmFkNDBjNmY4NDI5YTcwMzYxOWFjMjRhNjVjY2Y4ZmU3ZjY0ZTRlNmY3NzEzMGI2JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Y3wgAIysQisPaeNIYnI_DnOFNyr8ShvE8DuigoeOBaw)
๐ง1) [] -> ํ ๋ฒ ๊ฐ๋ผ์ง๋ ํธ๋ฆฌ ์กด์ฌ
=> ์์ญ์ด ์ ์ดํฉ = 2์ ๋ฐฐ์
๐ง2) [[]] -> ์ค๋ฅธ์ชฝ ์์ ํธ๋ฆฌ์ ์์ญ์ด ์ ์ดํฉ = 2์ ๋ฐฐ์
-> ์ผ์ชฝ ์์ ํธ๋ฆฌ์ ์์ญ์ด ์ ์ดํฉ = 2์ ๋ฐฐ์
=> ์์ญ์ด ์ ์ดํฉ = 4์ ๋ฐฐ์
=> ํธ๋ฆฌ๊ฐ ๋๋์ด์ง ๋๋ง๋ค ์์ญ์ด์ ์๊ฐ 2๋ฐฐ ํ์ํจ
๐ฉต3. ์๊ฐํ ์ ์๋ ํ์ด ๋ฐฉ๋ฒ๐ฉต
=> ํธ๋ฆฌ์ ๊น์ด์ ๊ด๋ จ์ด ์์!
=> ์ตํ์ ๋ ธ๋๋ก๋ถํฐ ๋งจ ์๊น์ง์ ๊ฐ๋ฆผ๊ธธ์ด ์ต๋ N๊ฐ ์กด์ฌํ๋ฉด, ์์ญ์ด ์์ ์ดํฉ = 2^N์ ๋ฐฐ์
๐ฉต4. ์ต์ข ์ฝ๋๐ฉต
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
ํธ๋ฆฌ์ ๊น์ด๋ฅผ ๊ตฌํ ๋, ํ์ฌ ๊น์ด๋ฅผ ์ธก์ ํ๋ ๋ณ์๋ฅผ ํ๋ ๋ ํ,
์ฃผ์ด์ง ๊ดํธ ๋ฌธ์์ด์์ ์ฌ๋ ๊ดํธ([)๊ฐ ๋์ค๋ฉด ์ฆ๊ฐ์ํค๊ณ ,
๋ซ๋ ๊ดํธ(])๊ฐ ๋์ค๋ฉด ๊ฐ์์ํค๋ฉด์,
๊ทธ ์ค ๋ฑ์ฅํ๋ ์ ์ผ ํฐ ๊ฐ์ด ๊น์ด๊ฐ ๋๋๋ก ํ์ฌ ๊ตฌํ ์ ์๋ค๋ ๊ฒ์ ์๊ฒ ๋์๋ค.