第一个只出现一次的字符

来源:互联网 发布:mac的终端文件路径 编辑:程序博客网 时间:2024/06/07 22:17
//很简单,直接哈希#include <iostream>using namespace std;char count_first(char str[]){    int i=0;    int count[256] = {0};    while(str[i]!='\0')    {        count[str[i]]++;        ++i;    }    for(i=0;i<256;++i)    {        if(count[i]==1)            break;    }    return i;}int main(){    char str[1024];    memset(str,'\0',1024);    while(cin>>str)    {        cout<<count_first(str)<<endl;    }    return 0;}