URI C 로 푸는데 질문이요!!!!!!

  • chubichubi
    chubichubi

    안녕하세요!!! 초보 C 배우고 있는 개발자입니다. ㅠ.ㅠ

    다름이아니라, 테스트 케이스를 다 넣어봤는데

    일단 %2520 >> %20 으로 나오게도 넣어보고

    %2520 >> 공백 으로 나오게도 넣어봤습니다.

    어떤 부분이 잘못됬는지 계속 제출해도 오답이 떠서 ㅠㅠ
    체크해주시길 바라며 이렇게 처음으로 글을 올려봅니다. ㅠㅠ

    질문하는 글을 제대로 작성했는지 모르겠네요 ㅠ.ㅠ 좀 두서없더라도 체크좀 해주시길 부탁드려요~!!!!! ㅠ.ㅠ
    (개행도 지워보고, 배열 문자수도 바꿔보고 했는데도 안되서 ㅠㅠ 20번은 제출한것같아요 ㅠㅠ)

    include
    include
    (여기는 # 같이 넣으니까 문법때문에 이상하게 표시되서 헤더에서 #뺏어용 stdio.h 랑 string.h 추가했습니당.)
    int main ()
    {
    int C;
    int i;
    char str[100][81]={0};
    char *tmp;
    char *ptr;

    scanf("%d", &C);
    
    for(i=0;i<C;i++){
    scanf("%s",str[i]);
    
        while(strstr(str[i],"%20")!=NULL){
            ptr=strstr(str[i],"%20");
            tmp = ptr+3;
            strncpy(ptr," ",1);
            strcpy(ptr+1,tmp);
            }
        while(strstr(str[i],"%21")!=NULL){
            ptr=strstr(str[i],"%21");
            tmp = ptr+3;
            strncpy(ptr,"!",1);
            strcpy(ptr+1,tmp);
            }
        while(strstr(str[i],"%24")!=NULL){
            ptr=strstr(str[i],"%24");
            tmp = ptr+3;
            strncpy(ptr,"$",1);
            strcpy(ptr+1,tmp);
            }
        while(strstr(str[i],"%28")!=NULL){
            ptr=strstr(str[i],"%28");
            tmp = ptr+3;
            strncpy(ptr,"(",1);
            strcpy(ptr+1,tmp);
            }
        while(strstr(str[i],"%29")!=NULL){
            ptr=strstr(str[i],"%29");
            tmp = ptr+3;
            strncpy(ptr,")",1);
            strcpy(ptr+1,tmp);
            }
        while(strstr(str[i],"%2a")!=NULL){
            ptr=strstr(str[i],"%2a");
            tmp = ptr+3;
            strncpy(ptr,"*",1);
            strcpy(ptr+1,tmp);
            }
        while(strstr(str[i],"%25")!=NULL){
            ptr=strstr(str[i],"%25");
            tmp = ptr+3;
            strncpy(ptr,"%",1);
            strcpy(ptr+1,tmp);
            }
            printf("%s\n", str[i]);
    }

    }


    9년 전
2개의 댓글이 있습니다.
  • Kureyo
    Kureyo

    소스시작하기 전줄에 ~~~ c++ 넣고 소스 끝나고 난 줄 뒤에 ~~~ 를 넣으면 c++ 스타일로 하이라이팅이 되니 참고해주세요


    9년 전 link
  • JongMan
    JongMan

    코드의 문제에 관해서라면.. strcpy() man page에 이런 내용이 있습니다 참조해 주세요.

    DESCRIPTION
    The stpcpy() and strcpy() functions copy the string src to dst (including the terminating `\0' character).

    The stpncpy() and strncpy() functions copy at most n characters from src into dst.  If src is less than n
     characters long, the remainder of dst is filled with `\0' characters.  Otherwise, dst is not terminated.
    
    *The source and destination strings should not overlap, as the behavior is undefined.*

    마지막 줄에 주목해 주세요.


    9년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.