string

🔒 문제 🔑 풀이 (C++) #include #include #include #define MIN_VALUE 0 #define MAX_VALUE 255 using namespace std; bool has_only_digits(const string s){ // dot(.) == "\000" return s.find_first_not_of( "0123456789" ) == string::npos && (s != "\000"); } /* The function returns 1 if IP string is valid else return 0 You are required to complete this method */ int isValid(string s) { if (count(s.begin(), s.en..
🔒 문제 구분자가 .이 아니라 ' ' 공백이 여러개 들어왔을 경우에 뒤집는 풀이 🔑 풀이 (C++) #include #include using namespace std; string reverseWords(string S) { int endIndex = S.length(); string result = ""; while (endIndex > 0) { while (endIndex > 0 && S[endIndex--] == ' '); int startIndex = endIndex; while (startIndex > 0 && S[--startIndex] != ' '); if (startIndex != 0) { string word = S.substr(startIndex + 1, endIndex - start..
🔒 문제 💭 생각의 흐름 배열은 선형 자료구조로 전체 길이 / 2를 기준으로 좌우 대칭을 이루고있다. 맨 첫자리 끝자리 첫자리 + 1 끝자리 - 1 index를 사용하여 대칭을 이루는 문자열을 Swapping 해주기만 하면 된다. 🔑 풀이 (C++) string reverseWord(string str){ char characterArray[str.length() + 1]; const int length = sizeof(characterArray); strncpy(characterArray, str.c_str(), length); // after strncpy null-terminate character should not be created characterArray[length] = '\0'; for..
M_Falcon
'string' 태그의 글 목록