daily pastebin goal
41%
SHARE
TWEET

Mare1

a guest Jan 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. ifstream cin("mare1.in");
  10. ofstream cout("mare1.out");
  11.  
  12. string v[105];
  13. string s = "", aux, maxx = "";
  14.  
  15. bool palindrom(string s) {
  16.     for(int i = 0; i < s.size()>>1; i++) {
  17.         if(s[i] != s[s.size()-i-1]) {
  18.             return 0;
  19.         }
  20.     }
  21.     return 1;
  22. }
  23.  
  24. int main()
  25. {
  26.     int n;
  27.     cin >> n;
  28.  
  29.     for(int i = 0; i < n; i++) {
  30.         cin >> v[i];
  31.     }
  32.  
  33.     for(int i = 0; i < n; i++) {
  34.         s = v[i];
  35.         for(int j = i+1; j < n; j++) {
  36.             s += v[j];
  37.             if(palindrom(s))
  38.             {
  39.                 if(s.size() > maxx.size())
  40.                     maxx = s;
  41.                 else if(s.size() == maxx.size()) {
  42.                     for(int k = 0; k < s.size(); k++) {if(s[k] > maxx[k]) maxx = s; break; }
  43.                 }
  44.             }
  45.         }
  46.     }
  47.  
  48.     cout << maxx;
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top