Computer/Algorithm

Daily Algorithm - 확장자 확인하기

kentakang 2018. 4. 7. 10:42
반응형

문제

정보검색실에서 노트북으로 문서를 작성하던 광곽이는 갑자기 어떠한 파일의 확장자를 보고 이 확장자가 어떤 파일인지 잊어버렸다.

광곽이가 파일.확장자를 입력하면 이게 어떤 프로그램인지 알 수 있도록 도와주자.

광곽이는 대소문자에 예민하다!

확장자 종류  
.dib : Paint.Picture  
.doc : Word.Document.8  
.docx : Word.Document.12  
.htm : htmfile  
.html : htmlfile  
.hwp : Hwp.Document.96  
.hwpx : Hwp.Document.hwpx.96  
.hwt : Hwp.Document.hwt.96  
.jpe, .jpeg, .jpg : jpegfile  
.ppt : PowerPoint.Show.8  
.pptx : PowerPoint.Show.12  
.pptxml : powerpointxmlfile

입력

파일.확장자의 형태로 입력된다.

파일명은 알파벳 대소문자와 숫자로만 구성되고, 입력은 100글자 이하이다.

출력

프로그램의 영문 이름을 출력한다. (출력명은 명령프롬프트에 ASSOC를 쳤을 때 나오는 결과에 따른다.)

예제 입력

codeup.pptx

예제 출력

PowerPoint.Show.12

풀이


#include <stdio.h>
#include <string.h>

int main()
{
int n = 0;
char fileName[100];
char extension[6];

scanf("%s", fileName);

for (int i = 0; i < strlen(fileName); i++)
{
if (fileName[i] == '.')
{
n = i;
break;
}
}

for (int i = n + 1; i < strlen(fileName) + 1; i++)
{
if (i == strlen(fileName))
extension[(i - n) - 1] = '\0';
else
{
extension[(i - n) - 1] = fileName[i];
}
}

if (strcmp("dib", extension) == 0)
{
printf("Paint.Picture");
}
else if (strcmp("doc", extension) == 0)
{
printf("Word.Document.8");
}
else if (strcmp("docx", extension) == 0)
{
printf("Word.Document.12");
}
else if (strcmp("htm", extension) == 0)
{
printf("htmfile");
}
else if (strcmp("html", extension) == 0)
{
printf("htmlfile");
}
else if (strcmp("hwp", extension) == 0)
{
printf("Hwp.Document.96");
}
else if (strcmp("hwpx", extension) == 0)
{
printf("Hwp.Document.hwpx.96");
}
else if (strcmp("hwt", extension) == 0)
{
printf("Hwp.Document.hwt.96");
}
else if (strcmp("jpe", extension) == 0 || strcmp("jpeg", extension) == 0 || strcmp("jpg", extension) == 0)
{
printf("jpegfile");
}
else if (strcmp("ppt", extension) == 0)
{
printf("PowerPoint.Show.8");
}
else if (strcmp("pptx", extension) == 0)
{
printf("PowerPoint.Show.12");
}
else if (strcmp("pptxml", extension) == 0)
{
printf("powerpointxmlfile");
}
}


문제 출처 : http://codeup.kr/JudgeOnline/problem.php?id=1755



반응형