ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 - 8958 OX퀴즈
    백준 algorithm 2019. 12. 27. 12:29

    문제 설명

    입력을 받으면서 OX라는 벡터에 결과값을 계산해서 집어넣은 후 마지막에 출력하는 방식으로 하였다. 
    O가 연소갷서 나올경우 더하는 값을 증가하며 sum을 증가시키고, X가 나올경우 tmp2를 초기화 시킨다. 

    #include <iostream>
    #include <vector>
    #include <string>
    using namespace std;
    
    
    int main()
    {
    	int N;
    	cin >> N;
    	vector<int> OX;//vector to save value
    	for (int i = 0; i < N; i++)
    	{
    		string tmp;
    		cin >> tmp;
    		int sum = 0;
    		int tmp2=0;
    		for (int i = 0; i < tmp.length(); i++)
    		{
    			if (tmp[i] == 'O')
    			{
    				tmp2++;
    				sum += tmp2;
    			}
    			else
    			{
    				//sum += tmp2;
    				tmp2 = 0;
    			}
    		}
    		OX.push_back(sum);
    	}
    
    	for (int i = 0; i < OX.size(); i++)
    	{
    		cout << OX[i] << '\n';
    	}
    }

    '백준 algorithm' 카테고리의 다른 글

    백준 2908 상수  (0) 2020.01.08
    백준 1546 - 평균  (0) 2019.12.31
    백준 - 11022 A+B -8  (0) 2019.12.27
    백준 2742 - 기찍 N  (0) 2019.12.27
    백준 2884 -알람시계  (0) 2019.12.27

    댓글

Designed by Who.