|
만해 님이 쓰신 글 :
: 안녕하세요 만해 입니다.
:
: 김백일님 답변 감사 드립니다.
:
: 지금
:
: deque<bool> mask(128);
:
: 이렇게 정의 해서 쓰고 있는데요
:
: 알고리즘에 있는 rotate를 사용하고 있습니다.
:
: 그런데 이 rotate가 left rotate 같네요 맞겠죠~
:
: 이 반대 역활을 하는 함수가 필요한데요
:
: 그러니깐 roght rotate가 필요한데
:
: rotate(mask.begin(),mask.begin()+6,mask.end());
rotate(mask.begin(), mask.end() - 6, mask.end());
으로 하면 됩니다.
: mask.begin()+6 <- 여기다 -6값을 넣으니깐 바로 에러가 나고요
:
: 혹 해서
:
: reverse(mask.begin(),mask.end);
: rotate(mask.begin(),mask.begin()+6,mask.end());
:
: 이렇게 해 봤는데
:
: 전혀 아닌값이 나오고요
:
: 기존의 rotate의 반대 역활을 하는 함수를 직접 구현 해야 하나요?
:
: 아니면 기존의 rotate에서 뭔가 조금 바꾸면 되나요?
:
: 좀 알려주세요
:
: 부탁 드릴께요 그럼 이만
'STL Tutorial and Reference Guide, Second Editon'에 있는 예제를 적습니다.
참고하세요.
// Illustrating the generic rotate algorithm
#include <cassert>
#pragma hdrstop
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main()
{
cout << "Illustrating the generic rotate algorithm." << endl;
string s("Software Engineering ");
vector<char> vector1(s.begin(), s.end());
// Rotate leftly the vector so that "Engineering " comes first:
rotate(vector1.begin(), vector1.begin() + 9, vector1.end());
assert(string(vector1.begin(), vector1.end()) ==
string("Engineering Software "));
cout << " --- Ok." << endl;
// Rotate rightly the vector so that "Software " comes first:
rotate(vector1.begin(), vector1.end() - 9, vector1.end());
assert(string(vector1.begin(), vector1.end()) ==
string("Software Engineering "));
cout << " --- Ok." << endl;
return 0;
}
|