회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
이렇게 풀어도 되는건가여...? 어디를 고쳐야 할까요
25192번 - 인사성 밝은 곰곰이
ajhk1200
2년 전
0
이런식으로 풀면 안되나요..? 혹시 어디를 고쳐야 하나요
#include<stdio.h> #include<stdlib.h> #include<string.h> #define _CRT_SECURE_NO_WARNINGS struct bucket* hashtable = NULL; struct node { char key[21]; struct node* next; }; struct bucket { struct node* head; int count; }; void creatnode(int len, char key[21]) { struct node* newnode = (struct node*)malloc(sizeof(struct node)); strcpy(newnode->key, key); if (hashtable[len].count == 0) { hashtable[len].head = newnode; hashtable[len].count = 1; } else { newnode->next = hashtable[len].head; hashtable[len].head = newnode; hashtable[len].count += 1; } } int search(int len, char key[21]) { struct node* node = NULL; if (hashtable[len].head == NULL) { return 1; } else { node = hashtable[len].head; while (1) { if (node == NULL) { break; } if (strcmp(node->key, key) == 0) { return 0; } node = node->next; } } return 1; } int main() { hashtable = (struct bucket*)malloc(sizeof(struct bucket) * 900000); int A = 0; int all = 0; scanf("%d", &A); for (int i = 0; i < A; i++) { char name[21]; scanf("%s", name); if (strcmp(name, "ENTER") == 0) { free(hashtable); hashtable = (struct bucket*)malloc(sizeof(struct bucket) * 900000); continue; } int len = strlen(name); int slen = 0; for (int j = 0; j < len; j++) { slen += name[j]; } all += search(slen, name); creatnode(slen, name); } printf("%d",all); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
ajhk1200 2년 전
이런식으로 풀면 안되나요..? 혹시 어디를 고쳐야 하나요