[PPProject] 첫 번째 만남의 결과물 ---- [[TableOfContents]] == 문제 == 컬럼 2. B번 문제 n개의 원소를 가지는 1차원 벡터를 i만큼 왼쪽으로 회전시켜라. === [Leonardong] === {{{~cpp #include #include using namespace std; void roll( string str, int i ); void main() { string str = "abcde"; int i = 3; roll(str, i); } void roll( string str, int i ) { cout << str << endl; int n = str.length(); char temp; for ( int tag = 0 ; tag < n ; tag++ ){ temp = str[tag]; str[tag] = str[i-1]; str[i-1] = temp; i = i < n ? i+1 : i; } cout << str << endl; } }}} === 재선 회영 === {{{~cpp #include #include void roll(int i); char * string="ABCDEFGHIJKLMNOPQRSTUV"; const int SIZE = strlen(string); void main() { roll(4); } void roll(int i) { char* buffer1 = new char[i]; strncpy(buffer1, string, i); buffer1[i] = 0; char *buffer2 = new char[SIZE-i]; strcpy(buffer2,string+i); cout<