반응형

USACO Uddered but not Herd

백준 20973

문제

www.acmicpc.net/problem/20973

 

20973번: Uddered but not Herd

A little known fact about cows is that they have their own version of the alphabet, the "cowphabet". It consists of the 26 letters 'a' through 'z', but when a cow speaks the cowphabet, she lists these letters in a specific ordering that might be different

www.acmicpc.net

코드

import java.util.Scanner;

public class Main {

    // USACO Uddered but not Herd JAVA
    // 백준 20973

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String cowStr = sc.nextLine();
        String target = sc.nextLine();
        int cnt = 0;    //answer

        int idx = 0;    //target 전용 idx

        while (idx < target.length()) {
            ++cnt;
            for (int i = 0; i < cowStr.length(); i++) {
                if (cowStr.charAt(i) == target.charAt(idx)) ++idx;
                if (idx >= target.length()) break;
            }
        }

        System.out.println(cnt);

    }

}//class


반응형

'개발 > 알고리즘' 카테고리의 다른 글

[USACO] Mad Scientist JAVA  (0) 2021.02.23
[USACO] Even More Odd Photos JAVA  (0) 2021.02.23
[USACO] Swapity Swap JAVA  (0) 2021.02.23
[USACO] Triangles JAVA  (0) 2021.02.22
[프로그래머스] 모의고사 JAVA  (0) 2021.02.21
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기