๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[Codeforces] 978B: File Name

by ์ฃผ๋ฐœ2 2020. 3. 11.
๋ฐ˜์‘ํ˜•

https://codeforces.com/problemset/problem/978/B

 

Problem - 978B - Codeforces

 

codeforces.com

์ฝ”๋“œ

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String str = scan.next();
		int delete = 0;

		// ๋ฌธ์ž์—ด์—์„œ "xxx"๊ฐ€ ์žˆ์„๋•Œ => delete ํ•œ๊ฐœ์”ฉ ์ฆ๊ฐ€.
		for(int i=0; i<str.length()-2; i++) 
			if(str.charAt(i) == 'x' && str.charAt(i+1) == 'x' && str.charAt(i+2) == 'x') 
				delete ++;
		
		System.out.println(delete);
		scan.close();
	}

}

ํ’€์ด

 If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.

๋ฌธ์ œ์—์„œ 3๊ฐœ์ด์ƒ์˜ "x"๋ฅผ ํฌํ•จํ•  ๋•Œ, ํŒŒ์ผ์€ ๋ณด๋‚ด์งˆ ์ˆ˜ ์—†๋‹ค. "xxx"๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š๋„๋ก ๋ฌธ์ž๋ฅผ ์ตœ์†Œํ•œ ์ง€์šฐ๊ธฐ.

 

์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์„ ํƒ์ƒ‰ํ•˜๋ฉด์„œ "xxx"์ผ๋•Œ, ํ•œ๊ฐœ์”ฉ ์ง€์šฐ๋ฉด ๋œ๋‹ค.

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€