OO -> 1+2

OX -> 1+0

OXO -> 1+0+1

OOOO-> 1+2+3+4

test  

5
OOXXOXXOOO
OOXXOOXXOO
OXOXOXOXOXOXOX
OOOOOOOOOO
OOOOXOOOOXOOOOX

output


10
9
7
55
30

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int testCase = sc.nextInt();

sc.nextLine();

String[] input = new String[testCase];

int count =0;

int sum=0;

int[] sumArr = new int[testCase];

int buff;

for(int i=0;  i<testCase ; i++ ){

input[i] = sc.nextLine();

for(int j=0; j<input[i].length() ; j++){

if(input[i].charAt(j) == 'O'){

count++;

input[i]=input[i].replaceFirst("O", ""+ count);

buff= count;

}else{

input[i]=input[i].replaceFirst("X", "0");

count=0;

buff= 0;

}

sum += buff;

}

sumArr[i] = sum;

count=0;

sum=0;

}

for(int i=0;  i<testCase ; i++ ){

System.out.println(sumArr[i]);

}

System.out.println(Arrays.toString(input));

}



'오락기 > codeWar' 카테고리의 다른 글

백준 2920  (0) 2018.05.03
백준 2577  (0) 2018.04.25
백준4673  (0) 2017.12.29
백준 설탕문제  (0) 2017.11.07
7  (0) 2017.08.31

+ Recent posts