博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在一个字符串中找到第一个只出现一次的字符
阅读量:4095 次
发布时间:2019-05-25

本文共 472 字,大约阅读时间需要 1 分钟。

题目:在一个字符串中找到第一个只出现一次的字符,如输入abaccdeff,则输出b;具体实现如下:

[cpp] 
 
  1. #include <iostream>  
  2. #include <string>  
  3. using namespace std;  
  4. void FindChar(const string &strBuf)  
  5. {  
  6.     int nArr[256];  //ASCII中有256个字符  
  7.     int i;  
  8.     for (i = 0; i < 256; i++)  
  9.     {  
  10.         nArr[i] = 0;  
  11.     }  
  12.     for (i = 0; i < strBuf.size(); i++)  
  13.     {  
  14.         nArr[strBuf[i]]++;  
  15.     }  
  16.     for (i = 0; i < 256; i++)  
  17.     {  
  18.         if (nArr[i] == 1)  
  19.         {  
  20.             cout<<(char)i<<endl;  
  21.             return;  
  22.         }  
  23.     }  
  24. }  
  25. int main()  
  26. {  
  27.     string str = "dfdsa4qwerfsdasdf4vwers";  
  28.     FindChar(str);  
  29.     system("pause");  
  30.     return 0;  
  31. }  

转载地址:http://pmoii.baihongyu.com/

你可能感兴趣的文章
configure: error: Please reinstall the BZip2 distribution
查看>>
OpenCV gpu模块样例注释:video_reader.cpp
查看>>
【增强学习在无人驾驶中的应用】
查看>>
《python+opencv实践》四、图像特征提取与描述——29理解图像特征
查看>>
《python+opencv实践》四、图像特征提取与描述——30Harris 角点检测
查看>>
《python+opencv实践》四、图像特征提取与描述——31 Shi-Tomasi 角点检测& 适合于跟踪的图像特征
查看>>
OpenCV meanshift目标跟踪总结
查看>>
人工神经网络——神经元模型介绍
查看>>
人工神经网络——感知器介绍
查看>>
人工神经网络——反向传播算法(BackPropagation)
查看>>
进程的地址空间概述
查看>>
Windows 窗口底层原理
查看>>
一种函数指针的运用
查看>>
Win32程序之进程的原理
查看>>
C++虚函数原理
查看>>
MySQL的索引
查看>>
今天,Python信息量很大!
查看>>
Flash 已死,Deno 当立?
查看>>
编程差的程序员,90%都是吃了数学的亏!骨灰级开发:方法不对,努力也白费...
查看>>
编程差的程序员,90%都是吃了数学的亏!骨灰级开发:方法不对,努力也白费...
查看>>