代码.

/*
     因为字符共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;
}

 

相关文章:

  • 2022-12-23
  • 2021-10-19
  • 2022-01-13
  • 2021-10-18
  • 2022-12-23
猜你喜欢
  • 2021-10-05
  • 2021-08-28
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-07-31
相关资源
相似解决方案