17 找一个字符串中第一个之出现一次的字符

代码.

/*
     因为字符共256种可能,记录每个字符出现的次数,然后找到第一次出现1次的就是
 */
#include<string>
#include<iostream>
using namespace std;

void getfirst(string str)
{
    unsigned int count[256];
    int i;

    for(i=0;i<256;i++)
        count[i]=0;

    for(i=0;i<str.size();++i)
        count[(unsigned int)str[i]]++;

    for(i=0;i<256;++i)
        if(count[i]==1)
        {
            cout<<(char)i<<endl;
            break;
        }
}

int main(void)
{
    string s;

    cin>>s;
    getfirst(s);
    return 0;
}
原文地址:https://www.cnblogs.com/buxianghe/p/3210858.html