-
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
[구현 & 코너케이스] 09월 20일 #4
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
using namespace std; | ||
|
||
bool wordchecker(string s) { | ||
vector<bool> check(26, false); | ||
char temp; | ||
|
||
for (int i = 0; i < s.length(); i++) { | ||
if (check[s[i] - 'a'] == false) { | ||
check[s[i] - 'a'] = true; | ||
} | ||
else { | ||
if (temp != s[i]) { | ||
return false; | ||
} | ||
} | ||
temp = s[i]; | ||
} | ||
return true; | ||
} | ||
|
||
int main() { | ||
vector<bool> check(26, false); | ||
int n; | ||
cin >> n; | ||
|
||
int count = 0; | ||
|
||
for (int i = 0; i < n; i++) { | ||
string s; | ||
cin >> s; | ||
if (wordchecker(s) == true) { | ||
count++; | ||
} | ||
} | ||
|
||
cout << count; | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
#include <vector> | ||
using namespace std; | ||
|
||
string getWheel(int n, int k) { | ||
vector<char> wheel(n, '?'); | ||
vector<char> check(26, false); | ||
|
||
int point = 0; | ||
|
||
for (int i = 0; i < k; i++) { | ||
int cnt; | ||
char letter; | ||
cin >> cnt >> letter; | ||
cnt %= n; | ||
point -= cnt; | ||
if (point < 0) { | ||
point += n; | ||
} | ||
if (wheel[point] != '?' && wheel[point] != letter) { | ||
return "!"; | ||
} | ||
else | ||
wheel[point] = letter; | ||
} | ||
|
||
for (int i = 0; i < wheel.size(); i++) { | ||
if (wheel[i] == '?') | ||
continue; | ||
if (check[wheel[i] - 'A'] == false) { | ||
check[wheel[i] - 'A'] = true; | ||
} | ||
else | ||
return "!"; | ||
} | ||
|
||
string answer = ""; | ||
|
||
for (int i = 0; i < wheel.size(); i++) { | ||
|
||
answer += wheel[(i + point)%n]; | ||
} | ||
return answer; | ||
} | ||
|
||
int main() { | ||
int n, k; | ||
cin >> n >> k; | ||
|
||
cout << getWheel(n, k); | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <stack> | ||
using namespace std; | ||
|
||
string getPassword(string s) { | ||
|
||
stack<char> front; | ||
stack<char> back; | ||
|
||
while (!front.empty()) { | ||
front.pop(); | ||
} | ||
while (!back.empty()) { | ||
back.pop(); | ||
} | ||
|
||
Comment on lines
+10
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3. 초기화할 필요가 없는 것 같아요! 매 s 마다 스택이 생성되기 때문입니다 |
||
for (int i = 0; i < s.length(); i++) { | ||
if (s[i] == '<') { | ||
if (!front.empty()) { | ||
back.push(front.top()); | ||
front.pop(); | ||
} | ||
} | ||
|
||
else if (s[i] == '>') { | ||
if (!back.empty()) { | ||
front.push(back.top()); | ||
back.pop(); | ||
} | ||
} | ||
|
||
else if (s[i] == '-') { | ||
if (!front.empty()) { | ||
front.pop(); | ||
} | ||
} | ||
|
||
else { | ||
// ������ �Է� | ||
front.push(s[i]); | ||
} | ||
} | ||
|
||
while (!front.empty()) { | ||
back.push(front.top()); | ||
front.pop(); | ||
} | ||
|
||
string password; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3. 변수 선언은 stack 선언할 때 같이 묶어서 해주면 좋을 것 같습니다. |
||
|
||
while (!back.empty()) { | ||
password += back.top(); | ||
back.pop(); | ||
} | ||
|
||
return password; | ||
} | ||
|
||
int main() { | ||
int n; | ||
cin >> n; | ||
|
||
while (n--) { | ||
string s; | ||
cin >> s; | ||
cout << getPassword(s) << '\n'; | ||
} | ||
|
||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
using namespace std; | ||
|
||
int getSize(string s) { | ||
int top = 0, bottom = 0, left = 0, right = 0; | ||
int dir = 0; // ���� | ||
vector<int> point(4, 0); // �� �� �� �� ��� | ||
|
||
for (int i = 0; i < s.length(); i++) { | ||
if (s[i] == 'F') { | ||
point[dir % 4]++; | ||
point[(dir + 2) % 4]--; | ||
} | ||
else if (s[i] == 'B') { | ||
point[dir % 4]--; | ||
point[(dir + 2) % 4]++; | ||
} | ||
else if (s[i] == 'L') { | ||
dir += 3; | ||
} | ||
else if (s[i] == 'R') { | ||
dir++; | ||
} | ||
|
||
if (point[0] > top) { | ||
top = point[0]; | ||
} | ||
if (point[1] > right) { | ||
right = point[1]; | ||
} | ||
if (point[2] > bottom) { | ||
bottom = point[2]; | ||
} | ||
if (point[3] > left) { | ||
left = point[3]; | ||
} | ||
Comment on lines
+9
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p2. 조건에 따라 방향을 잘 구현해주셨네요!!✨✨
위와 같이 선언해주시면 방향 배열의 인덱스를 활용해 회전을 구현할 수 있습니다. (채원님께서 구현해주신 것과 비슷한 느낌으로요!) |
||
} | ||
|
||
int size = (top + bottom) * (right + left); | ||
return size; | ||
} | ||
|
||
int main() { | ||
int n; | ||
cin >> n; | ||
|
||
for (int i = 0; i < n; i++) { | ||
string s; | ||
cin >> s; | ||
cout << getSize(s) << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
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.
p2. 특정 알파벳을 이미 방문한 경우와 연속된 문자열 아닌 경우를 먼저 처리하여 return 하면 인덴테이션이 깊어지지 않을 수 있어요!