fork(1) download
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. string rev(string s)
  6. {
  7. string ans=" ";
  8. for(int i=s.length();i>=0;i--)
  9. ans = ans + s[i];
  10. return ans;
  11. }
  12. char print(string x)
  13. {
  14. return x[(x.length()-1)/2]; //Returns the character at the middle position of a given string
  15. }
  16. int main()
  17. {
  18. int n;
  19. cin>>n;
  20. vector<string>v;
  21. string str;
  22. for(int i=0;i<n;i++)
  23. {
  24. cin>>str;
  25. v.push_back(str);
  26. }
  27. for(int i=0;i<n;i++)
  28. {
  29. if(find(v.begin(),v.end(),rev(v[i]))!=v.end()) // String found yo
  30. {
  31. int len = v[i].length();
  32. cout<<"v[i] =" <<v[i]<<"\n";
  33. cout<<len<<" "<<print(v[i])<<endl;
  34. break;
  35. }
  36. }
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 3232KB
stdin
4
abc
cba
def
fed
stdout
Standard output is empty