지우너
[코드트리] G&H 반전시키기 C++ 본문
문제
https://www.codetree.ai/missions/8/problems/reversing-g-and-h?&utm_source=clipboard&utm_medium=text
코드트리 | 코딩테스트 준비를 위한 알고리즘 정석
국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.
www.codetree.ai
코드
#include <iostream>
using namespace std;
int n;
string initStr, targetStr;
int main() {
cin >> n >> initStr >> targetStr;
// 목표 str과 다른 문자 그룹의 수(answer)
int checkIdx=0, answer=0;
while(checkIdx<n){
// 다르면
if(initStr[checkIdx]!=targetStr[checkIdx]){
while(checkIdx+1<n && initStr[checkIdx]!=targetStr[checkIdx]){
checkIdx++;
}
answer++;
}
checkIdx++;
}
cout << answer << '\n';
return 0;
}
'Problem Solving' 카테고리의 다른 글
[코드트리] 상하좌우 반전시키기 C++ (0) | 2024.09.11 |
---|---|
[코드트리] 좌우 반전시키기 C++ (0) | 2024.09.10 |
[코드트리] 회의실 겹치지 않게 하기 C++ (0) | 2024.09.09 |
[코드트리] 자동차 단일 거래 이익 최대화하기 2 C++ (0) | 2024.09.08 |
[코드트리] 수 채우기 C++ (0) | 2024.09.08 |