Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package anagram;
- import java.util.Scanner;
- public class Anagram {
- static String s1="";
- static String s2="";
- static char[] str1;
- static char[] str2;
- public static void main(String[] args) {
- Scanner Sc=new Scanner(System.in);
- s1=Sc.nextLine();
- s2=Sc.nextLine();
- str1=new char[s1.length()];
- str2=new char[s2.length()];
- //Chuyen chuoi 1 vao mang char
- for(int i=0;i<s1.length();i++)
- {
- str1[i]=s1.charAt(i);
- }
- //Chuyen chuoi s2 vao mang char
- for(int j=0;j<s2.length();j++)
- {
- str2[j]=s2.charAt(j);
- }
- //Chuyen het ky tu ? o chuoi 1 xuong duong cuoi
- int t=s1.length();
- for(int k=s1.length()-1;k>=0;k--)
- {
- t--;
- if(s1.charAt(k)!='?') break;
- }
- for(int i=0;i<=s1.length();i++)
- {
- if(str1[i]=='?')
- {
- char tempt=str1[i];
- str1[i]=str1[t];
- str1[t]=tempt;
- t--;
- }
- if(i>=t) break;
- }
- //Xu ly xau
- if(s1.length()!=s1.length()) System.out.println("(s1,s2)=false");
- else
- {
- for(int i=0;i<=t;i++)
- {
- boolean test=false;
- for(int j=i;j<s2.length();j++)
- {
- if(str2[j]==str1[i])
- {
- char tempt=str2[i];
- str2[i]=str2[j];
- str2[j]=tempt;
- test=true;
- }
- }
- if(test==false)
- {
- System.out.println("(s1,s2)=false");
- return;
- }
- }
- System.out.println("(s1,s2)=true");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement