Advertisement
Ankit_132

D

Sep 27th, 2023
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         ll int n;
  14.         string s, t;
  15.         cin>>n>>s>>t;
  16.  
  17.         int seg = 0, i = 0;
  18.  
  19.         while(i<n)
  20.         {
  21.             if(s[i]!=t[i])
  22.             {
  23.                 while(i<n && s[i]!=t[i])
  24.                     i++;
  25.  
  26.                 seg++;
  27.             }
  28.             else
  29.                 i++;
  30.         }
  31.  
  32.         if(seg==1)
  33.         {
  34.             ll val = (n-1)*1ll*2;
  35.             cout<<val<<"\n";
  36.         }
  37.         else if(seg==0)
  38.             cout<<(n*1ll*(n+1)/2)<<"\n";
  39.         else if(seg>2)
  40.             cout<<0<<"\n";
  41.         else
  42.             cout<<6<<"\n";
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement