Skip to content

초급반 / 김민지 / 단어뒤집기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
wants to merge 3 commits 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
93 changes: 93 additions & 0 deletions week7/implementation/단어뒤집기2/arenran02/Main.c
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;
}
26 changes: 26 additions & 0 deletions week7/implementation/파일정리/arenran02/Main.cpp
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;
}
75 changes: 75 additions & 0 deletions week7/simulation/ZOAC3/arenran02/Main.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

문자별 좌표와 해당 손 정보를 구조체로 관리하고, 이를 바탕으로 거리를 계산하고 손의 위치를 업데이트하는 방식이 좋다고 생각합니다. 군더더기 없이 구현된 좋은 코드입니다.

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();

}