favicon Jay Lee DevLog

📚 목차
#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 가 같을 경우에 리턴해주는 부분이랑,

결과 값이 매칭되는게 없을 경우를

잘 처리해줘야 한다는 것 정도가 되지 않을까 싶다.

 

이것도 다른 사람 풀이과정보면

정말 쉽게 푼 사람이 있는데

잘하는 사람들이 참 많은 것 같다.

+ Recent posts

/ /

Contact

📧 dlwjdwls60@naver.com


블로그에 내용이 있으면 해당 글을 보여주며, 없으면 내용이 복사된 채로 ChatGPT로 연결됩니다.