首页 > 其他 > 详细

第一个只出现一次的字符

时间:2014-07-24 09:59:53      阅读:288      评论:0      收藏:0      [点我收藏+]

题目:在字符串中找出第一个只出现一次的字符。如输入"abaccdeff",这输出‘b‘

// 第一个只出现一次的字符

#include <stdio.h>

char first_not_repeat_char(char *s)
{
    int count[256]={0};
    char *pkey;

    if( s==NULL )
    {
        printf("The string should not be NULL\n");
        return \0;
    }

    for(pkey=s; *pkey != \0; pkey++)
        count[*pkey]++;
    for(pkey=s; *pkey != \0; pkey++)
        if( count[*pkey] == 1 )
            return *pkey;

    return \0;
}

int main(void)
{
    char s[1001];
    printf("Please input a string: ");
    scanf("%s",s);
    char first = first_not_repeat_char(s);
    if(first != \0)
        printf("First not repeat char is: %c\n",first);
    else
        printf("Not found\n");
    char *p=0;

    return 0;
}

 

bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣

第一个只出现一次的字符,布布扣,bubuko.com

第一个只出现一次的字符

原文:http://www.cnblogs.com/DayByDay/p/3864419.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!