회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
AccessNullPointer 런타임 에러
7785번 - 회사에 있는 사람
jin0621050
2년 전
0
처음 겪는 런타임 에러라 대처를 어떻게 해야 할지 모르겠습니다. 도와주세요.
#include <stdio.h> #include <string.h> #include <stdlib.h> #define SIZE 10000 struct node{ int key; char* name; int el; struct node* next; }; struct bucket{ int count; struct node* head; }; struct bucket* hashtable = NULL; struct node* createNode(int key, char name[], int el){ struct node* newNode; newNode = (struct node*)malloc(sizeof(struct node)); newNode->key = key; newNode->name = strdup(name); newNode->el = 1; newNode->next = NULL; } int makekey(char name[]){ int hash = 143; for(;*name;name++){ hash = 5 * hash + *name; } return hash % 200000000; } int hashfunction(int key){ return key % SIZE; } void insert(char name[]){ int key = makekey(name); int hashIndex = hashfunction(key); struct node* newNode = createNode(key, name, 1); if(hashtable[hashIndex].count == 0){ hashtable[hashIndex].count = 1; hashtable[hashIndex].head = newNode; } else{ hashtable[hashIndex].count++; newNode->next = hashtable[hashIndex].head; hashtable[hashIndex].head = newNode; } } void erase(char name[]){ int key = makekey(name); int hashIndex = hashfunction(key); struct node* node = hashtable[hashIndex].head; while(node != NULL){ if(node->key == key && node->el == 1){ node->el = 0; break; } node = node->next; } } int main(){ hashtable = (struct bucket*)malloc(sizeof(struct bucket) * SIZE); for(int i=0; i<SIZE; i++){ hashtable[i].head = NULL; hashtable[i].count = 0; } int n; scanf("%d", &n); char name[6], el[6]; for(int i=0; i<n; i++){ scanf("%s %s", name, el); if(strcmp(el, "enter") == 0){ insert(name); } else{ erase(name); } } for(int i=0; i<SIZE; i++){ struct node* node = hashtable[i].head; while(node != NULL){ if(node->el == 1){ printf("%s\n", node->name); } node = node->next; } } }
댓글을 작성하려면
로그인
해야 합니다.
jin0621050 2년 전
처음 겪는 런타임 에러라 대처를 어떻게 해야 할지 모르겠습니다. 도와주세요.