문제 : https://www.acmicpc.net/problem/8958



import java.util.Scanner;
public class Main {
 public static void main (String [] args ) {
	 int num = 0;
	 int total[][];	 

	 Scanner scan = new Scanner (System.in);
	 num = scan.nextInt();
	 scan = scan.skip("[\\n\\r]+");
	 total = new int[num][2];
	 String answer ="" ;
	 int weight = 0;
	 
	 for(int i = 0; i <num ; i ++) {
		  answer = scan.nextLine();
		 answer = answer.replaceAll("O", "1");
		 answer = answer.replaceAll("X", "0");		 

		 for(int j = 0 ; j < answer.length(); j++) { 
			 if(Character.getNumericValue(answer.charAt(j)) == 1) {
				 total[i][1]++;
				 if( j != 0 && Character.getNumericValue( answer.charAt(j-1)) == 1 ) {
					 weight = weight+Character.getNumericValue( answer.charAt(j));
				 } else {
					 weight = 0;
				 }		
				 total[i][1] = weight +total[i][1];
			 }
		 }
	 } 
	 for(int i = 0 ; i < total.length; i++) {
		 System.out.println(total[i][1]);
	 }
   }
 }

+ Recent posts

"여기"를 클릭하면 광고 제거.