Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define pub push_back
- #include<bits/stdc++.h>
- bool isPalindrome (string s){
- string t= s;
- reverse ( s.begin(),s.end());
- return t== s;
- }
- int main() {
- string s;
- getline(cin,s);
- stringstream ss(s);
- string t;
- vector<string > v;
- map<string, int > mp;
- int count =0;
- while ( ss>> t) {
- count ++ ;
- if ( isPalindrome (t) ){
- mp[t]=count;
- }
- }
- for (auto x:mp){
- v.pub(x.first);
- }
- for (int i=0;i<v.size();i++){
- for (int j=i+1;j<v.size();j++){
- if ( v[i].size()> v[j].size()){
- swap(v[i],v[j]);
- }
- else if ( v[i].size() == v[j].size()){
- if (mp[v[i]] > mp[v[j]]){
- swap (v[i],v[j]);
- }
- }
- }
- }
- for (auto x: v){
- cout<<x<<" ";
- }
- /* Enter your codfore here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment