字串处理操作,用到了stl的排序和去重 #include <cstdio> #include <cstring> #include <vector> #include <string> #include <iostream> #include <algorithm> using namespace std; int fib[]={1,2,3,5,8,13,21,34,55,89}; vector<string>sub; int main() { char line[210]; while(scanf("%s",line)!=EOF) { sub.clear(); int len = strlen(line); for(int i = 0; i < len; i++) for(int j = i; j < len; j++) { int low[30]={0},sum = 0,flag = 0; for(int k = i; k <= j; k++) low[line[k]-'a'] ++; for(int k = 0; k < 26; k++) if(low[k]) sum++; for(int k = 0; k < 10; k++) if(sum == fib[k]) { flag = 1; break; } if(flag) { string tmp=""; for(int k = i; k <= j; k++) tmp+=line[k]; sub.push_back(tmp); } } sort(sub.begin(),sub.end()); vector<string>::iterator it_u = unique(sub.begin(),sub.end()); sub.erase(it_u,sub.end()); vector<string>::iterator it=sub.begin(),ed = sub.end(); for(;it != ed; it++) { cout<<*it<<endl; } } return 0; }