View

λ°˜μ‘ν˜•

문제λ₯Ό λ„ˆλ¬΄ μ‰½κ²Œ μƒκ°ν–ˆλ”λ‹ˆ μ‹œκ°„μ΄ˆκ³Ό

λ²”μœ„λ₯Ό λ³΄λ‹ˆ λ¬΄μ‹ν•˜κ²Œ ν’€λ©΄ μ•ˆλ˜κ² μŒ -> μˆœμ—΄λ„ μ•ˆλ λ“―

μ’€ 더 μƒκ°ν•΄λ³΄μž

package λ°±μ€€;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main_1593 {
	public static void main(String[] args) throws IOException {

		// W: cAda
		// g: 4
		// S:AbrAcadAbRa
		// gS: 11

		// Acad
		// cadA

		// λ‹€λ₯Έ 방법을 생각해야함

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int wSize = Integer.parseInt(st.nextToken());
		int sSize = Integer.parseInt(st.nextToken());
		int cnt = 0;
		String w = br.readLine();
		char[] wC = w.toCharArray();
		String s = br.readLine();
		char[] sC = s.toCharArray();
		char[] tmp = new char[w.length()];

		// λ¬Έμžμ—΄ μ •λ ¬
		Arrays.sort(wC);
		int i = 0;
		int j = 0;

		while (j < sC.length) {
			int k = 0;
			for (j = i; j < i + wC.length; j++) {
				tmp[k] = sC[j];
				k++;
			}
			Arrays.sort(tmp);
			if (Arrays.equals(tmp, wC)) {
				cnt += 1;
			}
			i += 1;
		}
		System.out.println(cnt);
	}
}

 

 

πŸ’‘ 두 λ°°μ—΄μ˜ λ‚΄μš©μ΄ 같은지 비ꡐ

if (Arrays.equals(tmp1, tmp2))
λ°˜μ‘ν˜•
Share Link
reply
λ°˜μ‘ν˜•
Β«   2024/11   Β»
일 μ›” ν™” 수 λͺ© 금 ν† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30