https://www.acmicpc.net/problem/2607
나의풀이
import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int answer=0;
int cnt = Integer.parseInt(st.nextToken());
String[] arr= new String[cnt];
for(int i=0; i<cnt ; i++){
st = new StringTokenizer(br.readLine());
arr[i]= st.nextToken();
}
char[] temp= arr[0].toCharArray();
for(int i=1; i<cnt; i++){
int same=0;
List<Character> originCopy= new ArrayList<>();//첫번째 단어
for(char t:temp){
originCopy.add(t);
}
char[] temp2= arr[i].toCharArray();
List<Character> now= new ArrayList<>(); //비교할 현재 대상
for(char t:temp2){
now.add(t);
}
Iterator<Character> it=now.iterator();
while(it.hasNext()){
char tempc=it.next();
if(originCopy.contains(tempc)){
same++;
int idx=originCopy.indexOf(tempc);
originCopy.remove(idx);
}
}
if(same == temp.length && same == now.size() && originCopy.size() == 0){
answer++;
}else if(same == temp.length && same == now.size()-1 && originCopy.size() == 0){
answer++;
}else if(same == temp.length-1 && same == now.size() && originCopy.size() == 1){
answer++;
}else if(same == temp.length-1 && same == now.size()-1 && originCopy.size() == 1){
answer++;
}
}
bw.write(Integer.toString(answer));
bw.flush();
br.close();
bw.close();
}
}
'코테풀이' 카테고리의 다른 글
[백준] BOJ - 1522 문자열 교환 java 자바 풀이(실버1) (0) | 2023.04.04 |
---|---|
[백준] BOJ - 2164 카드2 java 자바 (실버4) (0) | 2023.04.02 |
[백준] BOJ - 11501 주식 java 자바 (실버2) (0) | 2023.04.02 |
[백준] BOJ - 10816 숫자 카드 2 java 자바 (실버4) (0) | 2023.03.21 |
[백준] BOJ - 2110 공유기 설치 자바 JAVA (골드 4) (0) | 2023.03.20 |