题目描述

有一些字串,有些对称,有些不对称,请将对称的串按长度排列。

输入描述

输入为多行,每行一个串,串的长度不超过200,处理到文件结束

输出描述

输出对称的串,并且按串的长度升序排列,如果串长度相同,则按输入的顺序输出

样例输入

123321
123454321
123
321
sdfsdfd
121212
\\dd\\

样例输出

123321
\\dd\\
123454321
代码如下(用到stable_sort)

#include<algorithm>
#include
<string>
#include
<vector>
using namespace std;
vector 
<string> s;
bool cmp(const string &a,const string &b)
{
    
return a.size()<b.size();
}
int main()
{
    
int n,i;
    
char tmp[202],a[202];
    n
=0;
    
while(gets(tmp)!=NULL){
        strcpy(a,tmp);
        strrev(a);
        
if(strcmp(a,tmp)==0)
            s.push_back(tmp);
    }
    stable_sort(s.begin(),s.end(),cmp);
    
for(i=0;i<s.size();i++)
        cout
<<s[i]<<endl;
    
return 0;
}

相关文章:

  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-08-07
猜你喜欢
  • 2022-01-08
  • 2022-02-08
  • 2021-11-29
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
相关资源
相似解决方案