Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.concurrent.TimeUnit;
  3. import java.io.*;
  4.  
  5. public class test31 {
  6.     public static void main(String[] s) throws IOException {
  7.         Scanner in = new Scanner(System.in);
  8.         int n = in.nextInt();
  9.        
  10.         for (int w=0; w<n; w++){
  11.             int k = in.nextInt();
  12.             String a = in.next();
  13.             String b = in.next();
  14.    
  15.             int c = 0; //the amount of numbers were not changed
  16.             for (int i = 0; i < Math.min(a.length(), b.length()); i++){
  17.                 if (a.charAt(i) == b.charAt(i)){
  18.                     c++;
  19.                 }else{
  20.                     break;
  21.                 }
  22.             }
  23.            
  24.             int r = (Math.min(a.length(), b.length()) - c) * 2 +
  25.                     (Math.max(a.length(), b.length())-Math.min(a.length(), b.length())); //min amount of changes to get the result
  26.            
  27.             if (k-r >= 0 && (k-r)%2 == 0){
  28.                 System.out.println("Yes");
  29.             }else{
  30.                 System.out.println("No");
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement