목록문자열 뒤집기 #리버싱 #reversing (1)
Game Tech Blog
문자열 뒤집기
간단한 문자열 처리 중 하나인 문자열 뒤집기 reverse 함수 등 이런게 존재한다고 하는데, 함수 사용하지 않고 직접 구현해보는 것이 좋기때문에 구현. #include using namespace std; #define max 100 int main(void) { char ch[max];// 문자배열 집합 char temp;// 임시변수 int length;// 길이 cin >> ch; while(ch[length] != NULL) length++; for(int = 0; i < (length/2); i++) { temp = ch[length -1 -i]; ch[length -1 -i] = ch[i]; ch[i] = temp; } // -1 의 경우 NULL문자를 고려, 문자배열은 0부터 시작 cout
Algorithm
2020. 11. 12. 20:49