| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11401 | vector and STL |
|
| 11447 | Use std::map |
|
Description
這是一個幫助你了解vector與STL的問題
基本上,除了output與read_input以外的所有function,都可以只用STL完成(就是連if和for loop都不用的意思),以下是function的介紹
- cat(lhs,rhs): 將lhs與rhs合併(lhs在前,rhs在後),並回傳合併後的結果
- erase_equivalent(vec): 移除vec裡面所有重複的數字(相同的數字只保留1個),並回傳移除後的結果
- 為了保證結果都相同,請先sort vec(由大至小)
- inter(lhs,rhs): 找出lhs與rhs的交集,並回傳該交集(由小至大)
- 假設lhs是3 2 2 2 1,rhs是4 2 2 1,則回傳1 2 2
- make_size_to(vec,new_size): 將vec的大小設定成new_size。如果new_size比原本的大小還大,則新的數字皆為0。如果new_size比原本的大小還小,則只保留前new_size個數字
- mix(lhs,rhs): 將lhs與rhs合併後,由大至小排序,並回傳排序後的結果
- odd_num_count(vec): 回傳vec裡面,數字為奇數的數字的數量
- output(vec): 輸出vec裡面的內容,每個數字後面伴隨著一個空白,輸出完整個vec後再伴隨著一個換行
- rotate_half(vec): 將vec前後互換,例如1 2 3 4要變成3 4 1 2;1 2 3要變成2 3 1。回傳互換後的結果
- read_input(vec): 利用cin讀入,並儲存到vec裡面。讀到0時表示輸入結束
- reverse(vec): 將vec反轉,例如1 2 3 4要變成4 3 2 1;1 2 3要變成3 2 1。回傳反轉後的結果
- sort(vec): 對vec做排序,由大至小
- sum(vec): 回傳vec所有元素的加總
以下三個網站可以幫助你寫完這次的作業
http://en.cppreference.com/w/cpp/container/vector
http://en.cppreference.com/w/cpp/algorithm
http://en.cppreference.com/w/cpp/header/iterator
Input
根據cpp的main function描述,做出相對應的function
Output
根據上述function輸出
Sample Input Download
Sample Output Download
Partial Judge Code
11401.cppPartial Judge Header
11401.hTags
Discuss
Description
This problem will help you understand how to use std::map.
http://en.cppreference.com/w/cpp/container/map
Notice, this time, first and last is [first, last].
目前有五個測資,第三筆測資不算,答題測資看另外四筆
Input
The input consist of series of command. Each commands is insert, range output or range erase.
insert: inserts a string (cmd) with the key (key) to map. If the key has already existed, insert the cmd at the begining of string (the string which the key belongs).
For example,
insert 0 "abc"
insert 1 "def"
the map should contain "abc", "def".
insert 0 "xyz"
the map should contain "xyzabc", "def".
range output: outputs the string from key (first) to key (last). Output a space character (' ') after printing an element.
range erase: erase the string from key (first) to key (last).
operator<<: outputs all strings in map. From the smallest key to biggest key. Output a space character (' ') after printing an element.
Output
Complete insert, output, erase and operator<<.