Guest User

Untitled

a guest
May 26th, 2018
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std ;
  4. typedef long long ll ;
  5. const int MX = 500500 ;
  6. char input1[MX] , input2[MX] ;
  7. string a , b ;
  8. int l ;
  9. bool rev( int i )
  10. {
  11.     return ( (a[l-1-i] == b[i]) && ( a[i] == b[l-i-1] ) ) ;
  12. }
  13. int main()
  14. {
  15.     int t ;
  16.     scanf("%d" , &t) ;
  17.     while( t-- )
  18.     {
  19.         scanf("%s" , input1) ;
  20.         a = (string)input1 ;
  21.         scanf("%s" , input2) ;
  22.         b = (string)input2 ;
  23.         l = a.length() ;
  24.         if( a.length() != b.length() )
  25.         {
  26.             printf("-1\n") ;
  27.             continue ;
  28.         }
  29.         if( a[l/2] != b[l/2] || ( l == 1 && ( a != b ) )  ){
  30.             printf("-1\n") ;
  31.             continue ;
  32.         }
  33.         int pr = 0 , ans = 0 ;
  34.         for( int i = 0 ; i < l / 2 ; ++i )
  35.         {
  36.             if( pr )
  37.                 swap( a[i] , a[l-1-i] ) ;
  38.             if( (a[i] == b[i]) && (a[l-1-i] == b[l-1-i]) )continue ;
  39.  
  40.             else if( rev(i) )
  41.             {
  42.                 ans++ ;
  43.                 pr = 1 - pr ;
  44.             }
  45.             else
  46.             {
  47.                 ans = -1 ;
  48.                 break ;
  49.             }
  50.         }
  51.         printf("%d\n",ans) ;
  52.     }
  53.     return 0 ;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment