給定一個只包含小寫字母的字符串,請你找到第一個僅出現一次的字符。若是沒有,輸出no。ios
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 }