[C++] 문자열을 숫자키로 변환
Updated:
개요
- 문자열을 숫자키로 변환
- 락 크기내에서 정해지므로 중복 가능
- 분배 등을 할 때 유용
예제
- 코드
-
#include <iostream> #include <string> using namespace std; int getKeyLockNumber(const string& strLockKey, const int& iLockSize) { return hash<string>()(strLockKey) % iLockSize; } int main() { cout << getKeyLockNumber("a", 10) << endl; cout << getKeyLockNumber("bb", 10) << endl; cout << getKeyLockNumber("ccc", 10) << endl; return 0; }
-
- 실행 결과
-
9 1 7
-