Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions 1316.cpp
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p2. 특정 알파벳을 이미 방문한 경우와 연속된 문자열 아닌 경우를 먼저 처리하여 return 하면 인덴테이션이 깊어지지 않을 수 있어요!

}

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;
}
53 changes: 53 additions & 0 deletions 2840.cpp
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;
}
72 changes: 72 additions & 0 deletions 5397.cpp
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

Choose a reason for hiding this comment

The 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;

Choose a reason for hiding this comment

The 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;
}
56 changes: 56 additions & 0 deletions 8911.cpp
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p2. 조건에 따라 방향을 잘 구현해주셨네요!!✨✨
현재 방법도 매우 좋지만, 방향은 방향 배열로 구현해주시면 구현이 편해질 거에요! 보통, 방향 배열은 아래처럼 많이들 표현합니다!

//북 동 남 서
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

위와 같이 선언해주시면 방향 배열의 인덱스를 활용해 회전을 구현할 수 있습니다. (채원님께서 구현해주신 것과 비슷한 느낌으로요!)
예를 들어, 북쪽은 0이니까 방향은 dx[0], dy[0] 가 되겠네요.
현재 위치가 (0, 0) 일 때 북쪽으로 한 칸 이동한다고 할 때,
현재 x좌표(0)+dx[0](0) , 현재 y좌표(0)+dy[0](1) 를 한다면 (0, 1) 가 되겠네요!

}

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;
}