[알고리즘/SWEA] #1289 원재의 메모리 복구하기

JudyLia·2022년 2월 3일
0

알고리즘

목록 보기
13/61
post-thumbnail

문제)
원재의 메모리 복구하기

package algorithm_lab.day01.q1;

import java.util.Scanner;
import java.io.File;
import java.io.FileInputStream;

class Solution
{
	public static void main(String args[]) throws Exception
	{
		
		/*
		   표준입력 System.in 으로부터 스캐너를 만들어 데이터를 읽어옵니다.
		 */
		Scanner sc = new Scanner(new File("./src/algorithm_lab/day01/input.txt"));
		int T;
		T=sc.nextInt();
		/*
		   여러 개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
		*/
		
		sc.nextLine();
		for(int test_case = 1; test_case <= T; test_case++)
		{
			String words=sc.nextLine();
			boolean isChange=false;
			char a='0';
			int count=0;
			
			for(int i=0;i<words.length();i++) {
				if(words.charAt(i)!=a) {
					count+=1;
					a=words.charAt(i);
				}
			}
			System.out.printf("#%d %d%n",test_case,count);

		}
	}
}
profile
안녕:)

0개의 댓글

관련 채용 정보