CF1520E.Arranging The Sheep

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length nn , consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move any sheep one square to the left or one square to the right, if the corresponding square exists and is empty. The game ends as soon as the sheep are lined up, that is, there should be no empty cells between any sheep.

For example, if n=6n=6 and the level is described by the string "**.*..", then the following game scenario is possible:

  • the sheep at the 44 position moves to the right, the state of the level: "**..*.";
  • the sheep at the 22 position moves to the right, the state of the level: "*.*.*.";
  • the sheep at the 11 position moves to the right, the state of the level: ".**.*.";
  • the sheep at the 33 position moves to the right, the state of the level: ".*.**.";
  • the sheep at the 22 position moves to the right, the state of the level: "..***.";
  • the sheep are lined up and the game ends.

For a given level, determine the minimum number of moves you need to make to complete the level.

输入格式

The first line contains one integer tt ( 1t1041 \le t \le 10^4 ). Then tt test cases follow.

The first line of each test case contains one integer nn ( 1n1061 \le n \le 10^6 ).

The second line of each test case contains a string of length nn , consisting of the characters '.' (empty space) and '*' (sheep) — the description of the level.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6 .

输出格式

For each test case output the minimum number of moves you need to make to complete the level.

输入输出样例

  • 输入#1

    5
    6
    **.*..
    5
    *****
    3
    .*.
    3
    ...
    10
    *.*...*.**

    输出#1

    1
    0
    0
    0
    9
首页