C/C++ code#include <iostream> #include <string> using namespace std; int main() { string s("agaabbbcccsdddefffg"); int appear=0; int appeared=0; int repeated=0; for(string::size_type i=0; i<s.length(); ++i) { appear |= 1<<(s.at(i)-'a');//当前出现 if(appear&appeared) repeated |= (appear & appeared);//有重复 appeared |= appear ;//以往出现 appear = 0; } appeared ^= repeated; for(char c=0; c<26; appeared>>=1,++c) { if(appeared&1) { cout<<(char)(c+'a')<<endl; break; } } return EXIT_SUCCESS; } #include<stdio.h> #include<string.h> int num[26]={0}; int index[26]={0}; int main() { char *s="abbbccdefafgg "; int i; for(i=0;i<strlen(s);i++) { num[s[i]-'a']++; index[s[i]-'a']=i; } int min=strlen(s),p=0; for(i=0;i<26;i++) if(num[i]==1 && index[i]<min) { min=index[i]; p=i; } printf("%c/n",p+'a'); return 0; }