C언어 문자열에 중복 문자 있는지 확인

John Jeong (토론 | 기여)님의 2017년 12월 29일 (금) 06:01 판 (새 문서: ==개요== ;Checking the duplicates in string ;문자열에서 중복 문자가 있는지 확인 ==예시== <source lang='C'> #include <stdio.h> #include <string.h> int allUnique(ch...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

Checking the duplicates in string
문자열에서 중복 문자가 있는지 확인

2 예시

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

int allUnique(char *str)
{
    int i, j;
    char *p = str;
    int l = strlen(str);

    for (i = 0; i < l - 1; i++) {
        for (j = i + 1; j < l; j++) {
            if (p[i] == p[j])
                return 0; 
        }
    }
    return 1; 
}

int main()
{
    printf("%d\n", allUnique("abcd")); // 1
    printf("%d\n", allUnique("abcc")); // 0

    return 0;
}

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}