思路很简单,滑动窗口扫描,扫描到‘.’直接跳过3个字符,安置一个路灯,扫描到‘X’,不处理跳过。
主要注意多个测试用例,可以一边输入测试用例,一边输出结果。
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n != 0) {
n--;
int len = sc.nextInt();
String s = sc.next();
System.out.println(s);
int index = 0;
int cnt = 0;
while (index < len) {
if(s.charAt(index) == '.'){
cnt++;
index += 3;
}else{
index++;
}
}
System.out.println(cnt);
}
}
} 
京公网安备 11010502036488号