首页 > 其他 > 详细

找出第一个只出现一次的字符串

时间:2015-09-18 21:44:58      阅读:101      评论:0      收藏:0      [点我收藏+]

#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
char find(char * str)
{
    if(str==NULL)
        return ‘\0‘;
    int hash[256];
    for(int i=0;i<256;i++)
        hash[i]=0;
    char *hashKey=str;
    while(*hashKey!=‘\0‘)
        hash[*(hashKey++)]++;
    hashKey=str;
    while(*hashKey!=‘\0‘)
    {
        if(hash[*hashKey]==1)
            return *hashKey;
        hashKey++;

    }
}
int main()
{
    char* a="afefcdd";
    char res=find(a);
    cout<<res;
    system("pause");
}

找出第一个只出现一次的字符串

原文:http://www.cnblogs.com/kangye/p/4820345.html

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