첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ HashMap 구조체를 사용해 우리말 월 이름을 처리하는 방법을 보여준다.

 

▶ 예제 코드 (RS)

use std::collections::HashMap;

fn main()
{
    let month_array = ["해오름달", "시샘달", "꽃내음달", "잎새달", "푸른달", "누리달", "빗방울달", "타오름달", "거둠달", "온누리달", "눈마중달", "매듭달"];

    let mut hashmap: HashMap<&str, usize> = HashMap::new();

    for (index, value) in month_array.iter().enumerate()
    {
        hashmap.insert(value, index + 1);
    }

    println!("누리달   = {:>2}월", hashmap["누리달"  ]);
    println!("온누리달 = {:>2}월", hashmap["온누리달"]);
    println!("매듭달   = {:>2}월", hashmap["매듭달"  ]);
}

/*
누리달   =  6월
온누리달 = 10월
매듭달   = 12월
*/
728x90
그리드형(광고전용)
Posted by icodebroker
,