Skip to content
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
80 changes: 80 additions & 0 deletions 10845번 - 큐
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_QUEUE_SIZE 10000

typedef struct {
int data[MAX_QUEUE_SIZE];
int front;
int back;
} Queue;

void initQueue(Queue *q) {
q->front = 0;
q->back = 0;
}

int isEmpty(Queue *q) {
return q->front == q->back;
}

int size(Queue *q) {
return q->back - q->front;
}

void push(Queue *q, int value) {
q->data[q->back++] = value;
}

int pop(Queue *q) {
if (isEmpty(q)) {
return -1;
}
return q->data[q->front++];
}

int front(Queue *q) {
if (isEmpty(q)) {
return -1;
}
return q->data[q->front];
}

int back(Queue *q) {
if (isEmpty(q)) {
return -1;
}
return q->data[q->back - 1];
}

int main() {
int n;
scanf("%d", &n);

Queue q;
initQueue(&q);

for (int i = 0; i < n; i++) {
char command[6];
scanf("%s", command);

if (strcmp(command, "push") == 0) {
int value;
scanf("%d", &value);
push(&q, value);
} else if (strcmp(command, "pop") == 0) {
printf("%d\n", pop(&q));
} else if (strcmp(command, "size") == 0) {
printf("%d\n", size(&q));
} else if (strcmp(command, "empty") == 0) {
printf("%d\n", isEmpty(&q));
} else if (strcmp(command, "front") == 0) {
printf("%d\n", front(&q));
} else if (strcmp(command, "back") == 0) {
printf("%d\n", back(&q));
}
}

return 0;
}
31 changes: 31 additions & 0 deletions 11866번 - 요세푸스 문제 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>

int main(void)
{
int n, k, i;
scanf("%d%d", &n, &k);
int a[n+1];
for(i = 1; i<=n; i++) a[i]=1;

printf("<");
i=1;
int count = 0;
int count_k = 0;
while(1)
{
if(a[i] == 1) count_k++;
if(a[i] == 1 && count_k == k) {
count_k = 0;
a[i] = 0;
count++;
if(count == n) {
printf("%d>", i);
break;
}
printf("%d, ", i);
}
i++;
if(i>n) i = i-n;
}
return 0;
}
76 changes: 76 additions & 0 deletions 202202545/1018번 - 체스판 다시 칠하기
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;
string WB[8] = {
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW"
};
string BW[8] = {
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB"
};
string board[50];
int WB_cnt(int x, int y)
{
int cnt = 0;
for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 8; j++)
{
if(board[x+i][y+j] != WB[i][j])
cnt++;
}

}
return cnt;
}
int BW_cnt(int x, int y)
{
int cnt = 0;
for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 8; j++)
{
if(board[x+i][y+j] != BW[i][j])
cnt++;
}

}
return cnt;
}
int main() {
int size[2];
int cnt;
int min_val = 12345;
pair<int, int> p1;
cin >> p1.first >> p1.second;
for(int i = 0; i < p1.first; i++)
cin >> board[i];
for(int i = 0; i + 8 <= p1.first; i++)
{
for(int j = 0; j + 8 <= p1.second; j++)
{
int tmp;
tmp = min(WB_cnt(i,j),BW_cnt(i,j));
if(tmp < min_val) {
min_val = tmp;
}
}
}
cout << min_val;
return 0;
}
26 changes: 26 additions & 0 deletions 202202545/10809번 - 알파벳 찾기
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <string.h>

int main() {
char word[101];
int positions[26];

scanf("%s", word);

// 모든 알파벳의 등장 위치 -1로 초기화
memset(positions, -1, sizeof(positions));

for (int i = 0; word[i] != '\0'; i++) {
int index = word[i] - 'a'; // 알파벳 인덱스 계산
if (positions[index] == -1) {
positions[index] = i;
}
}

// 결과 출력
for (int i = 0; i < 26; i++) {
printf("%d ", positions[i]);
}

return 0;
}
43 changes: 43 additions & 0 deletions 202202545/10814번 - 나이순정렬
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 회원 구조체 정의
typedef struct {
int age;
char name[101];
int order; // 가입 순서를 저장하는 필드
} Member;

int compare(const void *a, const void *b) {
Member *memberA = (Member *)a;
Member *memberB = (Member *)b;

if (memberA->age != memberB->age) {
return memberA->age - memberB->age; // 나이 오름차순 정렬
} else {
return memberA->order - memberB->order; // 가입 순서 오름차순 정렬
}
}

int main() {
int N;
scanf("%d", &N); // 회원의 수 입력

Member *members = (Member *)malloc(N * sizeof(Member)); // 동적 메모리 할당

for (int i = 0; i < N; i++) {
scanf("%d %s", &members[i].age, members[i].name);
members[i].order = i; // 가입 순서 저장
}

qsort(members, N, sizeof(Member), compare);

for (int i = 0; i < N; i++) {
printf("%d %s\n", members[i].age, members[i].name);
}

free(members);

return 0;
}
23 changes: 23 additions & 0 deletions 202202545/10818번 - 최대,최소
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>

int main() {
int N;
int min_value = 1000000;
int max_value = -1000000;

scanf("%d", &N);

for (int i = 0; i < N; i++) {
int num;
scanf("%d", &num);

if (num < min_value)
min_value = num;
if (num > max_value)
max_value = num;
}

printf("%d %d\n", min_value, max_value);

return 0;
}
75 changes: 75 additions & 0 deletions 202202545/10828번 - 스택
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <stdio.h>
#include <string.h>
#define stack_size 10001

int high = -1;
int stack[stack_size];

void push(int x)
{
high++;
stack[high] = x;
}
int empty()
{
if (high == -1)
return 1;
else
return 0;
}
int pop()
{
if (empty())
{
return -1;
}
else
{
return stack[high--];
}
}
int top()
{
if (empty())
return -1;
else
return stack[high];
}
int main()
{

int N = 0, push_data = 0;
char command[5] = {0, };

scanf("%d", &N);

for (int i = 0; i < N; i++)
{

scanf("%s", command);

if (!strcmp(command, "push"))
{
scanf("%d", &push_data);
push(push_data);
}
else if (!strcmp(command, "pop"))
{
printf("%d\n", pop());
}
else if (!strcmp(command, "empty"))
{
printf("%d\n", empty());
}
else if (!strcmp(command, "size"))
{
printf("%d\n", high + 1);
}
else if (!strcmp(command, "top"))
{
printf("%d\n", top());
}
}

return 0;
}
27 changes: 27 additions & 0 deletions 202202545/1157번 - 단어개수
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <ctype.h>

int main() {
int count[26] = {0};
char word[1000001];
char most_used = '?';
int max_count = 0;

scanf("%s", word);
for (int i = 0; word[i] != '\0'; i++) {
if (isalpha(word[i])) {
int index = tolower(word[i]) - 'a';
count[index]++;
if (count[index] > max_count) {
max_count = count[index];
most_used = toupper(word[i]);
} else if (count[index] == max_count) {
most_used = '?';
}
}
}

printf("%c\n", most_used);

return 0;
}
Loading