반응형
https://algospot.com/judge/problem/read/JEONGLIBE
algospot.com :: JEONGLIBE
정리 못하는 정리베 문제 정보 문제 알고스팟 새싹 콘테스트를 준비하느라 정신이 없던 정리베는, 버벅거리는 컴퓨터의 원인이 가득 찬 하드디스크라는 것을 알게 되었습니다. 하드의 파일들을
algospot.com
문자열을 split하고 formating하는 문제임.
string.h의 함수들을 사용함.
using namespace std;
vector S;
char* reformat(char *str)
{
int end = strlen(str);
char * pch = strrchr(str, '/');
int start = -1;
if (pch == NULL)
start = 0;
else
start = pch - str+1;
char buf[501];
strcpy(buf, &(str[start]));
int n = 0;
char strs[5][5001];
bool peak = false;
start = 0;
int next = strcspn(buf, "_.-");
while (start < strlen(buf))
{
switch (buf[next])
{
case '.':
if (peak){
strncpy(strs[n], buf + start + 1, next - start - 1);
strs[n++][next - start - 1] = '\0';
}
else{
strncpy(strs[n], buf + start, next - start);
strs[n++][next - start] = '\0';
}
peak = true;
break;
case '-':
if (peak){
strncpy(strs[n], buf + start + 1, next - start - 2);
strs[n++][next - start - 2] = '\0';
}
else{
strncpy(strs[n], buf + start, next - start - 1);
strs[n++][next - start - 1] = '\0';
}
peak = true;
break;
default:
if (peak){
strncpy(strs[n], buf + start + 1, next - start - 1);
strs[n++][next - start - 1] = '\0';
}
else{
strncpy(strs[n], buf + start, next - start);
strs[n++][next - start] = '\0';
}
peak = false;
break;
}
start = ++next;
next += strcspn(buf + start, "_.-");
}
buf[0] = '\0';
if (n == 4)
{
strcat(buf, strs[1]);
strcat(buf, "/");
strcat(buf, strs[2]);
}
else if (n == 3)
{
strcat(buf, strs[0]);
strcat(buf, "/");
strcat(buf, strs[1]);
}
return buf;
}
int main()
{
int n;
for (scanf("%d", &n), getchar(); n > 0; n--)
{
char buf[501];
gets(buf);
strcpy(buf, reformat(buf));
string s(buf);
transform(s.begin(), s.end(), s.begin(), ::tolower);
bool plag = true;
for (int i = 0; i < S.size(); i++){
if (s.compare(S[i]) == 0){
plag = false;
break;
}
}
if (plag)
S.push_back(s);
}
printf("%d\n", S.size());
return 0;
}
반응형