Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package anagram;
- import java.util.Scanner;
- public class Anagram {
- public static void main(String[] args) {
- Scanner Sc=new Scanner(System.in);
- String s1=Sc.nextLine();
- String s2=Sc.nextLine();
- char[] str1=new char[s1.length()];
- char[] 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=0;j<s2.length();j++)
- {
- if(str1[i]==str2[j]) 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