#include <stdio.h>#include <malloc.h>#define MAX_WORD_LEN 100#define MAX_FILENAME_NUM 50typedefstruct_node{intfileName;//몇번째 파일 명인가struct_node*next;}Node;typedefstruct_linkedList{Node*head;Node*before;Node*cur;}LinkedList;typedefLinkedListList;voidInput(void);voidSolve(void);intCompare(intidxInwildCardArr,intidxInFileNameArr,intfileNameNum);voidSaveArrAndSort(intfileNameArrNum);voidLInit(void);voidLDelete(void);intCompareArr(intfileNameArrNum1,intfileNameArrNum2);voidOutput(void);charwildCard[MAX_WORD_LEN+1];intlenOfWildCard;inttheNumberOfFileName;charfileName[MAX_FILENAME_NUM][MAX_WORD_LEN+1];intlenOfFileName[MAX_FILENAME_NUM];intdy[MAX_WORD_LEN][MAX_WORD_LEN];Listlist;intmain(void){inttc,T;freopen("input.txt","r",stdin);scanf("%d",&T);for(tc=1;tc<=T;tc++){Input();Solve();}return0;}voidSolve(void){intret;inti,j,k;LInit();for(i=0;wildCard[i]!=0;i++);lenOfWildCard=i;//와일드 카드 문자열의 길이 저장for(i=0;i<theNumberOfFileName;i++){for(j=0;fileName[i][j]!=0;j++);lenOfFileName[i]=j;//파일명 문자열의 길이 저장}for(i=0;i<theNumberOfFileName;i++){for(j=0;wildCard[j]!=0;j++)for(k=0;fileName[i][k]!=0;k++)dy[j][k]=-1;ret=Compare(0,0,i);if(ret==1)SaveArrAndSort(i);}Output();LDelete();}intCompare(intidxInwildCardArr,intidxInFileNameArr,intfileNameNum){if(idxInwildCardArr>=lenOfWildCard||idxInFileNameArr>=lenOfFileName[fileNameNum])return0;if(idxInwildCardArr==lenOfWildCard-1&&(wildCard[idxInwildCardArr]=='*'||(lenOfFileName[fileNameNum]-1==idxInFileNameArr&&(wildCard[idxInwildCardArr]==fileName[fileNameNum][idxInFileNameArr]||wildCard[idxInwildCardArr]=='?'))))return1;int&ret=dy[idxInwildCardArr][idxInFileNameArr];if(ret!=-1)returnret;ret=0;for(inti=idxInFileNameArr;i<lenOfFileName[fileNameNum];i++){if(wildCard[idxInwildCardArr]==fileName[fileNameNum][i]||wildCard[idxInwildCardArr]=='?')ret=(ret||Compare(idxInwildCardArr+1,i+1,fileNameNum));elseif(wildCard[idxInwildCardArr]=='*'){if(wildCard[idxInwildCardArr+1]=='*'||wildCard[idxInwildCardArr+1]=='?'||wildCard[idxInwildCardArr+1]==fileName[fileNameNum][i])ret=(ret||Compare(idxInwildCardArr+1,i,fileNameNum));}}returnret;}voidSaveArrAndSort(intfileNameArrNum){Node*node=(Node*)malloc(sizeof(Node));node->fileName=fileNameArrNum;node->next=0;if(list.head==0)list.head=node;else{list.cur=list.head;while(list.cur!=0&&CompareArr(list.cur->fileName,fileNameArrNum)){list.before=list.cur;list.cur=list.cur->next;}node->next=list.cur;if(list.cur==list.head)list.head=node;elselist.before->next=node;}}/*문자열 정렬 시, fileNameArrNum1가 사전순으로 더 빠르면 1, 아니면 0반환*/intCompareArr(intfileNameArrNum1,intfileNameArrNum2){for(inti=0;i<lenOfFileName[fileNameArrNum1];i++){if(i>=lenOfFileName[fileNameArrNum2])return0;if(fileName[fileNameArrNum1][i]<fileName[fileNameArrNum2][i])return1;elseif(fileName[fileNameArrNum1][i]>fileName[fileNameArrNum2][i])return0;}return1;}voidLInit(void){list.head=0;//링크드리스트 초기화list.before=0;list.cur=0;}voidLDelete(void){Node*delNode;Node*nextDelNode;delNode=list.head;while(delNode!=0){nextDelNode=delNode->next;free(delNode);delNode=nextDelNode;}}voidOutput(void){list.cur=list.head;while(list.cur!=0){printf("%s\n",fileName[list.cur->fileName]);list.cur=list.cur->next;}}voidInput(void){scanf("%s",wildCard);scanf("%d",&theNumberOfFileName);for(inti=0;i<theNumberOfFileName;i++)scanf("%s",fileName[i]);}
9년 전
0개의 댓글이 있습니다.
정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면
온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야
합니다. 현재 문제를 푸셨습니다.
chochogogo
해당 문제 관련해서 제가 간과한 부분이 있는지 여쭙니다...ㅠㅠ
수고하세요~
9년 전