牛客網2019筆試真題:安置路燈

安置路燈

. . .
. . x
. x .
x . .
x . x
x x .
. x x
以上情況都是一樣的,加一個路燈即可。

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- > 0) {
            int n = in.nextInt();
            in.nextLine();
            String r = in.nextLine();
            int count = 0;
            for(int i = 0;i < r.length();i++) {
                if(r.charAt(i) == '.') {
                    i += 2;
                    count++;
                }
            }
            System.out.println(count);
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章