fork(3) download
  1. //StdIn : 4 abc def fes cba
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <string>
  5. #include <unordered_map>
  6.  
  7. using namespace std;
  8. #define MAX 100
  9. string reverse(string temp){
  10. //cout<<" In function "<<temp;
  11. char pwd[temp.length()];
  12. int j=0;
  13. for(int i=(temp.length())-1;i>=0;i--,j++){
  14. pwd[j]=temp[i];
  15. }
  16. pwd[j]='\0';
  17. string str(pwd);
  18. return str;
  19. }
  20. int findPassword(string password[],int k){
  21. string temp;
  22. char *op;
  23. unordered_map<string, string> ht;
  24. for(int i=0;i<k;i++){
  25. if(password[i].length()%2 == 0 ) {cout<<"error in length" ; return 0 ;}
  26. temp=password[i];
  27. ht.insert(make_pair(temp,reverse(temp)));
  28. if(ht.find(reverse(temp))!=ht.end()){
  29. //cout<<temp<< "<=>" <<reverse(temp)<<endl ;
  30. cout<<password[i].length()<<" "<<temp[(password[i].length())/2];
  31. return 1;
  32. }//if
  33. }//for
  34. return 0;
  35. }
  36. int main(){
  37.  
  38. string password[MAX];
  39. unordered_map<string, string> ht;
  40.  
  41. int i=0, j=0, k=0, t=0;
  42. cin>>t;
  43. k=t;
  44. while(t){
  45. cin>>password[i];
  46. --t; ++i;
  47. }
  48. findPassword(password,k);
  49.  
  50. }//main
Success #stdin #stdout 0s 3436KB
stdin
4 abc def fes cba
stdout
3 b