Advertisement
Manh_LK

Anagram

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