Skip to content

Latest commit

 

History

History
71 lines (66 loc) · 2.64 KB

cpp.md

File metadata and controls

71 lines (66 loc) · 2.64 KB

C++

string에서 string 지우기

  • RLRRLLRR에서 "RR"들만 지우기.
  • boj5430번
void clean_p(string &p){
    auto pos = p.find("RR");
    while (pos != string::npos){
        p.erase(pos,2);
        pos = p.find("RR");
    }
}

iterator간의 ==연산

  • 결론: 주의해서 쓰자.
  • 하려했던것: left,right iterator를 만들어서 양쪽 끝에서 양쪽 끝에서 중간으로 한칸씩 이동시켜 가면서 left==right면 break하는 루프를 만들려 했음.
auto left = str.begin(); 
auto right = str.rbegin();
while (left!=str.end() and right!=str.rend()){
    if (left==right) break; //??????
    //...
    left++; 
    right++;
}

rbegin, rend

// for (auto it = company.begin(); it!=company.end(); it++)
//     cout << *it << '\n';
for (auto it = company.rbegin(); it!=company.rend(); it++){
    cout << *it << '\n';
}

long int vs long long int

a^b mod m 구현

using LLong = long long int;
LLong power(int a, int b, int m){
    LLong ret = 1;
    for (int i=0;i<b;i++)
        ret = (ret*a)%m;
    return ret;
}