Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; public class Exam_2_T_2 { public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String keyWord = scanner.nextLine();
- int countWords = Integer.parseInt(scanner.nextLine());
- String[] words = new String[countWords];
- int j = 0;
- for (int i = 0; i < countWords; i++) {
- words[i] = scanner.nextLine();
- }
- for (int i = 0; i < countWords; i++) {
- int length = words[i].length();
- int length2 = keyWord.length();
- String wordForChek = keyWord;
- int counter = 0;
- if (words[i].length() != keyWord.length()) words[i] = "No";
- else while ( length > 0 ) {
- if (wordForChek.charAt(j) == words[i].charAt(0)) {
- counter++;
- words[i] = words[i].substring(1);
- wordForChek = keyWord.substring(0, j) + keyWord.substring(j+1, length2);
- length = words[i].length();
- length2--;
- j = 0;
- if (counter == keyWord.length()) {
- wordForChek = keyWord; break; }
- continue;
- }
- j++; if ( j == length ) { wordForChek = keyWord; break; }
- }
- if (counter == keyWord.length()) words[i] = "Yes";
- else words[i] = "No";
- }
- for (String answer : words ) System.out.println(answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement