Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[2999] Re:[만해] 멀티맵에서의 범위 검색에 대해서 ... 자답입니다
강재호.만해 [greenuri] 1198 읽음    2003-10-06 14:29
안녕하세요 만해입니다.

역시 버그는 옆 사람이 잘 잡아 낸다는 말이 맞는것 같네요

메신저를 통해 여러분께 물어서

버그를 잡았습니다.

혹시나 다른분들도 필요한 내용일까 싶어서

소스 올려 드립니다.

//---------------------------------------------------------------------------
#include <iostream>
#pragma hdrstop
#include <iterator>
#include <functional>
#include <string>
#include <map>
#include <vector>
//---------------------------------------------------------------------------
using namespace std;
typedef std::multimap<string, string> TMMap;
typedef    TMMap::iterator TMMapIt;
typedef    std::pair<TMMapIt, TMMapIt> TMPair;
#pragma argsused
int main(int argc, char* argv[])
{
    typedef vector<string> vec_str;
    vec_str input_words, output_words;
    input_words.push_back("a");
    input_words.push_back("a");
    input_words.push_back("a");
    input_words.push_back("b");
    input_words.push_back("b");
    input_words.push_back("bb");
    input_words.push_back("c");
    input_words.push_back("c");
    input_words.push_back("c");

    typedef map<string, int> freq_map; // 여기서는 map 대신에 hash_map을 써도 좋습니다.
    freq_map freq;
    for (size_t i = 0; i < input_words.size(); ++i)
      freq[input_words[i]]++;

    typedef multimap<int, string> invert_freq_map;
    typedef multimap<int, string>::iterator miterator;
    typedef pair< miterator ,miterator > map_pair;
    map_pair pair1;
    invert_freq_map invert_freq;

    for (freq_map::iterator i = freq.begin(); i != freq.end(); ++i)
        invert_freq.insert(make_pair(i->second, i->first));

    pair1 = invert_freq.equal_range(3);
    // 찾고자 하는 키값이 3인 값들의 리스트를 받아 들이는 부분

    for ( miterator i = pair1.first ; i != pair1.second ; ++i)
        for (int j = 0; j < i->first; ++j) // 빈도만큼 output_words에 삽입
           output_words.push_back(i->second);

    copy(output_words.rbegin(), output_words.rend(),
         ostream_iterator<string>(cout, "\n")); // output_words를 cout에 출력

    TMMap m;
    m.insert(TMMap::value_type("one", "하나"));
    m.insert(TMMap::value_type("one", "일"));
    m.insert(TMMap::value_type("one", "1"));

    TMPair pr = m.equal_range("one");
    for(TMMapIt it = pr.first; it != pr.second; it++)
        cout << (((*it).second).c_str()) << endl;

    return 0;
}

+ -

관련 글 리스트
2987 [만해] 멀티맵에서의 범위 검색에 대해서 강재호.만해 1363 2003/09/30
4258     Re:[만해] 멀티맵에서의 범위 검색에 대해서 강재호.만해 1196 2003/10/04
2999     Re:[만해] 멀티맵에서의 범위 검색에 대해서 ... 자답입니다 강재호.만해 1198 2003/10/06
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.