Advertisement
Manh_LK

Anagram_Update

Dec 13th, 2019
1,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1.  
  2. package anagram;
  3. import java.util.Scanner;
  4.  
  5. public class Anagram {
  6.  
  7.  
  8.     static String s1="";
  9.     static String s2="";
  10.     static char[] str1;
  11.     static char[] str2;
  12.     public static void main(String[] args) {
  13.         Scanner Sc=new Scanner(System.in);
  14.         s1=Sc.nextLine();
  15.         s2=Sc.nextLine();
  16.         str1=new char[s1.length()];
  17.         str2=new char[s2.length()];
  18.         //Chuyen chuoi 1 vao mang char
  19.         for(int i=0;i<s1.length();i++)
  20.         {
  21.             str1[i]=s1.charAt(i);
  22.         }
  23.         //Chuyen chuoi s2 vao mang char
  24.         for(int j=0;j<s2.length();j++)
  25.         {
  26.             str2[j]=s2.charAt(j);
  27.         }
  28.         //Chuyen het ky tu ? o chuoi 1 xuong duong cuoi
  29.         int t=s1.length();
  30.         for(int k=s1.length()-1;k>=0;k--)
  31.         {
  32.             t--;
  33.             if(s1.charAt(k)!='?') break;
  34.         }
  35.         for(int i=0;i<=s1.length();i++)
  36.         {
  37.             if(str1[i]=='?')
  38.             {
  39.                 char tempt=str1[i];
  40.                 str1[i]=str1[t];
  41.                 str1[t]=tempt;
  42.                 t--;
  43.             }
  44.             if(i>=t) break;
  45.         }
  46.         //Xu ly xau
  47.         if(s1.length()!=s1.length()) System.out.println("(s1,s2)=false");
  48.         else
  49.         {
  50.             for(int i=0;i<=t;i++)
  51.             {
  52.                 boolean test=false;
  53.                 for(int j=i;j<s2.length();j++)
  54.                 {
  55.                     if(str2[j]==str1[i])
  56.                     {
  57.                         char tempt=str2[i];
  58.                         str2[i]=str2[j];
  59.                         str2[j]=tempt;
  60.                         test=true;
  61.                     }
  62.                 }
  63.                 if(test==false)
  64.                     {
  65.                         System.out.println("(s1,s2)=false");
  66.                         return;
  67.                     }
  68.             }
  69.             System.out.println("(s1,s2)=true");
  70.         }
  71.     }
  72.    
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement