글
백준 8958번 OX퀴즈(JAVA, C#) charAt(), array[].length()
자바
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int length = sc.nextInt();
String arr[] = new String[length];
int sum = 0;
int score = 0;
for(int i = 0;i<length;i++)
{
arr[i] = sc.next();
}
for(int i = 0;i<length;i++)
{
for(int j = 0;j<arr[i].length();j++)
{
if(arr[i].charAt(j) == 'O')
{
score++;
sum += score;
}
else
{
score = 0;
}
}
System.out.println(sum);
sum = 0;
score = 0;
}
}
}
///////////////////////////
C#
using System;
namespace Baekjoon {
class Program {
static void Main(string[] args) {
int length = int.Parse(Console.ReadLine());
int sum = 0;
int score = 0;
for(int i = 0;i<length;i++)
{
string ox = Console.ReadLine();
for(int j = 0;j<ox.Length;j++)
{
if(ox[j] == 'O')
{
score++;
sum += score;
}
else
{
score = 0;
}
}
Console.WriteLine(sum);
sum = 0;
score = 0;
}
}
}
}
'백준 프로그래밍' 카테고리의 다른 글
백준 15596번 정수 N개의 합(JAVA) 함수 (0) | 2023.02.18 |
---|---|
백준 4344번 평균은 넘겠지(JAVA, C#) %.3f%%\n / 100:F3}% (0) | 2023.02.18 |
백준 1546번 평균(JAVA, C#) BufferedReader (0) | 2023.02.18 |
백준 3052번 나머지(JAVA, C#) (0) | 2023.02.18 |
백준 5597번 과제 안 내신 분(JAVA, C#) (0) | 2023.02.16 |