본문 바로가기

Java/SWEA

[JAVA] SEWA 1926. 간단한 369 게임

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PTeo6AHUDFAUq&categoryId=AV5PTeo6AHUDFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=JAVA&select-1=2&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

정답 

 

import java.util.Scanner;

class Solution
{
	public static void main(String args[]) throws Exception
	{	
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int idx = 0;
		
		StringBuilder answer = new StringBuilder();
		String str[] = new String[N];
		
		for(int i=1; i<=N; i++)
		{
			str[idx++] = String.valueOf(i);
		}
		
		for(int i=0; i<str.length; i++)
		{
			if(str[i].contains("3")||str[i].contains("6")||str[i].contains("9"))
			{
				for(int j=0; j<str[i].length(); j++)
				{
					if(str[i].charAt(j)=='3'||str[i].charAt(j)=='6'||str[i].charAt(j)=='9')
					{
						answer.append("-");						
					}
				}
				answer.append(" ");
			}
			else
			{
				answer.append(str[i]).append(" ");
			}
		}
		
		
		System.out.println(answer.toString());

	}
}