📚 목차
#include <string>
#include <vector>
using namespace std;
int ShiftData(string strA, string strB)
{
string strResult{ "" };
if (strA == strB)
return 0;
int j = 1;
while (j < strA.size())
{
for (int i = 0; i < strA.size(); i++)
{
if (strA.size() - 1 == i)
strResult = strA[i] + strResult;
else
strResult += strA[i];
}
if (strResult == strB)
return j;
strA = strResult;
strResult = "";
j++;
}
return -1;
}
int solution(string A, string B) {
int answer = ShiftData(A, B);
return answer;
}
이것도 사실 풀이라고 할 것도 없긴한다.
그냥 문제에 나왔던 대로,
문자열을 한칸씩 미뤄주되,
마지막 문자일 경우에는
맨 앞으로 붙여주면 된다.
조심할거라면
A, B 가 같을 경우에 리턴해주는 부분이랑,
결과 값이 매칭되는게 없을 경우를
잘 처리해줘야 한다는 것 정도가 되지 않을까 싶다.
이것도 다른 사람 풀이과정보면
정말 쉽게 푼 사람이 있는데
잘하는 사람들이 참 많은 것 같다.
'C, C++ > 코딩테스트 입문 난이도' 카테고리의 다른 글
프로그래머스 코딩테스트 입문 난이도 - 7의 개수 (0) | 2023.06.25 |
---|---|
프로그래머스 코딩테스트 입문 난이도 - 잘라서 배열로 저장하기 (0) | 2023.06.25 |
프로그래머스 코딩테스트 입문 난이도 - 종이 자르기 (0) | 2023.06.25 |
프로그래머스 코딩테스트 입문 난이도 - 연속된 수의 합 (0) | 2023.06.25 |
프로그래머스 코딩테스트 입문 난이도 - 다음에 올 숫자 (0) | 2023.06.25 |