码迷,mamicode.com
首页 > 其他好文 > 详细

111

时间:2015-10-27 00:26:22      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4  
 5 void FindChar(string &s)
 6 {
 7     int str[256];
 8     for (int i=0;i<256;i++)
 9     {
10         str[i]=0;
11     }
12     for (int i=0;i<s.size();i++)
13     {
14         str[s[i]]++;
15     }
16     for (int i=0;i<s.size();i++)//多谢<a href="http://home.cnblogs.com/u/284122/" target="_blank">justinzhang</a>指出,第二次遍历时应从s中开始
17     {
18         if (str[s[i]]==1)
19         {
20             printf("%c",s[i]);
21             return;
22         }
23     }
24 }
25  
26  
27 int main()
28 {
29     string s;
30     cout<<"请输入字符串"<<endl;
31     cin>>s;
32     FindChar(s);
33     //cout<<FirstNotRepeatingChar(const_cast<char *>(s.c_str()));
34     cout<<endl;
35     system("pause");
36  
37     return 0;
38 }

 

111

标签:

原文地址:http://www.cnblogs.com/shengruxiahua/p/4912792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!