-
Notifications
You must be signed in to change notification settings - Fork 26
초급반 / 김민지 / 단어뒤집기2-17413, 파일정리-20291, ZOAC-30436 #108
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
Open
arenran02
wants to merge
3
commits into
Alom-codingTest:main
Choose a base branch
from
arenran02:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <ctype.h> | ||
|
||
// 노드 정의 | ||
typedef struct node { | ||
char data; | ||
struct node* next; | ||
} node; | ||
|
||
// 스택 구조체 | ||
typedef struct { | ||
node* top; | ||
int size; | ||
} STACK; | ||
|
||
// 스택 함수 정의 | ||
void init_STACK(STACK* s) { | ||
s->top = NULL; | ||
s->size = 0; | ||
} | ||
|
||
int is_stack_empty(STACK* s) { | ||
return s->size == 0; | ||
} | ||
|
||
void push_stack(STACK* s, char data) { | ||
node* newnode = malloc(sizeof(node)); | ||
newnode->data = data; | ||
newnode->next = s->top; | ||
s->top = newnode; | ||
s->size++; | ||
} | ||
|
||
char pop_stack(STACK* s) { | ||
if (is_stack_empty(s)) return '\0'; | ||
node* temp = s->top; | ||
char data = temp->data; | ||
s->top = temp->next; | ||
s->size--; | ||
free(temp); | ||
return data; | ||
} | ||
|
||
void flush_stack(STACK* s) { | ||
while (!is_stack_empty(s)) { | ||
printf("%c", pop_stack(s)); | ||
} | ||
} | ||
|
||
int main() { | ||
char str[100001]; | ||
fgets(str, sizeof(str), stdin); | ||
|
||
STACK s; | ||
init_STACK(&s); | ||
|
||
int in_tag = 0; | ||
|
||
for (int i = 0; str[i] != '\0'; i++) { | ||
char c = str[i]; | ||
|
||
if (c == '<') { | ||
// 단어 뒤집기 마무리하고 태그 출력 시작 | ||
flush_stack(&s); | ||
in_tag = 1; | ||
printf("%c", c); | ||
} | ||
else if (c == '>') { | ||
in_tag = 0; | ||
printf("%c", c); | ||
} | ||
else if (in_tag) { | ||
// 태그 안: 그대로 출력 | ||
printf("%c", c); | ||
} | ||
else { | ||
// 태그 밖 | ||
if (c == ' ' || c == '\n') { | ||
flush_stack(&s); | ||
printf("%c", c); | ||
} else { | ||
push_stack(&s, c); | ||
} | ||
} | ||
} | ||
|
||
// 마지막 남은 단어 뒤집기 | ||
flush_stack(&s); | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <iostream> | ||
#include <map> | ||
#include <string> | ||
|
||
int main() { | ||
int N; | ||
std::cin >> N; | ||
std::map<std::string, int> extensionCount; | ||
|
||
for (int i = 0; i < N; ++i) { | ||
std::string filename; | ||
std::cin >> filename; | ||
|
||
size_t pos = filename.rfind('.'); | ||
if (pos != std::string::npos) { | ||
std::string extension = filename.substr(pos + 1); | ||
++extensionCount[extension]; | ||
} | ||
} | ||
|
||
for (const auto& pair : extensionCount) { | ||
std::cout << pair.first << " " << pair.second << "\n"; | ||
} | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int map[3][10]; | ||
|
||
string top = "qwertyuiop"; | ||
string middle = "asdfghjkl"; | ||
string bottom = "zxcvbnm"; | ||
|
||
struct Info{ | ||
int r; | ||
int c; | ||
char hand; | ||
}; | ||
|
||
Info l, r; | ||
|
||
Info find_coor(char key){ | ||
int _r = 0, _c = 0; | ||
char hand; | ||
for(int i=0; i<top.length(); i++){ | ||
if(top[i] == key){ | ||
_r = 0, _c = i; | ||
if(i<=4) hand = 'l'; | ||
else hand = 'r'; | ||
} | ||
} | ||
for(int i=0; i<middle.length(); i++){ | ||
if(middle[i] == key){ | ||
_r = 1, _c = i; | ||
if(i <= 4) hand = 'l'; | ||
else hand = 'r'; | ||
} | ||
} | ||
for(int i=0; i<bottom.length(); i++){ | ||
if(bottom[i] == key){ | ||
_r = 2, _c = i; | ||
if(i <= 3) hand = 'l'; | ||
else hand = 'r'; | ||
} | ||
} | ||
return {_r, _c, hand}; | ||
} | ||
|
||
int find_dist(char key){ | ||
Info key_coor = find_coor(key); | ||
int dist = 0; | ||
if(key_coor.hand == 'l'){ | ||
dist = abs(l.r - key_coor.r) + abs(l.c - key_coor.c); | ||
l.r = key_coor.r; | ||
l.c = key_coor.c; | ||
} | ||
if(key_coor.hand == 'r'){ | ||
dist = abs(r.r - key_coor.r) + abs(r.c - key_coor.c); | ||
r.r = key_coor.r; | ||
r.c = key_coor.c; | ||
} | ||
return dist; | ||
} | ||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(0); | ||
|
||
char left, right; cin>>left>>right; | ||
string s; cin>>s; | ||
|
||
l = find_coor(left); | ||
r = find_coor(right); | ||
int ans = 0; | ||
for(char key: s) ans += find_dist(key); | ||
|
||
cout<<ans+s.length(); | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
문자별 좌표와 해당 손 정보를 구조체로 관리하고, 이를 바탕으로 거리를 계산하고 손의 위치를 업데이트하는 방식이 좋다고 생각합니다. 군더더기 없이 구현된 좋은 코드입니다.