K:找第一個只出現一次的字符

總時間限制: 
1000ms
 
內存限制: 
65536kB
描述

給定一個只包含小寫字母的字符串,請你找到第一個僅出現一次的字符。若是沒有,輸出no。ios

輸入
一個字符串,長度小於100000。
輸出
輸出第一個僅出現一次的字符,若沒有則輸出no。
樣例輸入
abcabd
樣例輸出
c
 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 int main()
 5 {
 6     string s;
 7     int a[100001] = { 0 }, i;
 8     cin >> s;
 9     for (i = 0; i < s.length(); ++i)
10     {
11         for (int j = 0; j < s.length(); ++j)
12         {
13             if (s[i] == s[j])
14             {
15                 a[i]++;
16             }
17         }
18         if (a[i] == 1)
19         {
20             cout << s[i];
21             return 0;
22         }
23     }
24 
25     cout << "no";
26 
27     return 0;
28 }
相關文章
相關標籤/搜索