문제 출처:https://www.acmicpc.net/problem/8958
8958번: OX퀴즈
"OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수
www.acmicpc.net

문제 분석
각 점수는 연속해서 정답인 경우 연속된 횟수만큼의 점수를 받습니다. 때문에 각 퀴즈별로 O를 몇번 연속으로 맞추는지 count해주어야 합니다. loop를 돌면서 count된 값들을 더해주면 무리없이 해결할 수 있습니다. 코드는 다음과 같습니다:
#include <iostream>
using namespace std ;
int main(){
ios::sync_with_stdio(false) ;
cin.tie(NULL) ; cout.tie(NULL) ;
int testcase, correct_cnt, total ;
string result ;
cin >> testcase ;
for(int i = 0 ; i < testcase ; i++){
correct_cnt = 0, total = 0 ;
cin >> result ;
for(auto c : result){
if(c != 'O')
correct_cnt = 0 ;
else{
correct_cnt += 1 ;
total += correct_cnt ;
}
}
cout << total << endl ;
}
return 0 ;
}
해당 문제는 Github에서도 보실 수 있습니다:
https://github.com/gurcks8989/CodingTest/blob/master/BackJoon/HPS/P8958_OXquiz.cpp
GitHub - gurcks8989/CodingTest: CodingTest_study_with_c++
CodingTest_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
훈수 및 조언은 언제든 환영입니다.
문제 출처:https://www.acmicpc.net/problem/8958
8958번: OX퀴즈
"OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수
www.acmicpc.net

문제 분석
각 점수는 연속해서 정답인 경우 연속된 횟수만큼의 점수를 받습니다. 때문에 각 퀴즈별로 O를 몇번 연속으로 맞추는지 count해주어야 합니다. loop를 돌면서 count된 값들을 더해주면 무리없이 해결할 수 있습니다. 코드는 다음과 같습니다:
#include <iostream>
using namespace std ;
int main(){
ios::sync_with_stdio(false) ;
cin.tie(NULL) ; cout.tie(NULL) ;
int testcase, correct_cnt, total ;
string result ;
cin >> testcase ;
for(int i = 0 ; i < testcase ; i++){
correct_cnt = 0, total = 0 ;
cin >> result ;
for(auto c : result){
if(c != 'O')
correct_cnt = 0 ;
else{
correct_cnt += 1 ;
total += correct_cnt ;
}
}
cout << total << endl ;
}
return 0 ;
}
해당 문제는 Github에서도 보실 수 있습니다:
https://github.com/gurcks8989/CodingTest/blob/master/BackJoon/HPS/P8958_OXquiz.cpp
GitHub - gurcks8989/CodingTest: CodingTest_study_with_c++
CodingTest_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
훈수 및 조언은 언제든 환영입니다.