문제 : https://www.acmicpc.net/problem/6965

 

6965번: Censor

The input to your program consists of an integer, n, on a line by itself, followed by n lines of text. Each line of text contains words separated by spaces. Each word consists of letters of the alphabet and exactly one space separates adjacent words. There

www.acmicpc.net

문제 요약 : 문자열중 4글자로 된 문자 변환

입력 출력
1 ≤ 각 문장 길이 ≤ 80
4글자로 된 문자를 ****로 치환 후 출력

JAVA

소스코드 : https://github.com/cbkpar/BOJ/blob/main/boj_6965.java

채점 번호 아이디 문제 번호 결과 메모리 시간 언어 코드 길이
30722726 cbkpar 6965 맞았습니다!! 14296KB 128ms Java 11 729B
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
		int n,i;
		n = Integer.parseInt(br.readLine());
		for(i=0;i<n;i++) {
			if(i!=0) sb.append("\n");
			StringTokenizer st = new StringTokenizer(br.readLine());
			boolean chk = false;
			while(st.hasMoreTokens()) {
				if(chk) sb.append(" ");
				String str = st.nextToken();
				sb.append(str.length()==4?"****":str);
				chk = true;
			}
			sb.append("\n");
		}
		System.out.println(sb);
	}
}

 

문장을 한줄씩 받고 공백을 기준으로 쪼개어 단어길이가 4인 경우에 ****로 치환해준다.

 

+ Recent posts