1 #include<iostream> 2 #include<vector> 3 #include<string> 4 #include<algorithm> //reverse所在头文件 5 using namespace std; 6 bool Comp(const string &str1,const string &str2) 7 { 8 if (str1.length()!=str2.length()) 9 return str1.length()<str2.length(); 10 else 11 return str1<str2; 12 } 13 int main() 14 { 15 vector<string> n; 16 string s,t; 17 while(cin>>s) 18 { 19 t=s; 20 reverse(t.begin(),t.end()); 21 if (t==s) 22 { 23 n.push_back(s); 24 } 25 26 } 27 sort(n.begin(),n.end(),Comp); 28 for (vector<string>::iterator v=n.begin();v!=n.end();v++) 29 { 30 cout<<*v<<endl; 31 } 32 }
1020 排列对称串
时间: 2024-11-10 21:08:47