본문 바로가기
JAVA

[백준/자바] 9933번 민균이의 비밀번호

by 동백05 2022. 1. 25.

#1일1알고리즘 24일차

https://www.acmicpc.net/problem/9933

 

9933번: 민균이의 비밀번호

첫째 줄에 단어의 수 N (2 ≤ N ≤ 100)이 주어진다. 다음 N개 줄에는 파일에 적혀있는 단어가 한 줄에 하나씩 주어진다. 단어는 알파벳 소문자로만 이루어져 있으며, 길이는 2보다 크고 14보다 작은

www.acmicpc.net

 

package algorithm;
import java.util.Scanner;
public class jan25 {
	public static void main(String[] args) {
		// BOJ 9933
		Scanner s = new Scanner(System.in);
		int number=s.nextInt();
		String arr[]=new String[number];
		for(int i=0;i<number;i++) {
			arr[i]=s.next();
		}
		int i=0;
		while(i<number) {
			StringBuffer pass=new StringBuffer(arr[i]);
			for(int j=0;j<number;j++) {
				StringBuffer word=new StringBuffer(arr[j]);
				if(pass.toString().equals(word.reverse().toString())) {
					String password=pass.toString();
					int middle=password.length()/2;
					System.out.print(password.length()+" "+password.substring(middle,middle+1));
					i=number;
				}
			}
			i++;
		}

	}

}

댓글