#include <iostream> #include <string.h> using namespace std; int main() { char input[100]; int count[26]; int i=0,j=0,pos; char ans[26]; memset(count,0,sizeof(count)); cin>>input; while(input[i]!=‘\0‘) { pos=input[i]-‘a‘; count[pos]++; if(count[pos]==2) ans[j++]=input[i]; i++; } ans[j]=‘\0‘; for(i=0;i<strlen(ans);i++) printf("%c",ans[i]); }
原文地址:http://mrcage.blog.51cto.com/6836193/1564416