有些內容使用中英雙語,有些只有英文或中文。歡迎使用與分享任何內容,但先來信告知並標示此部落格為出處。
Some parts use both Chinese and English, but some parts use only one language. Feel free to share, but please contact me first and list this blog as your reference.
顯示具有 Map (STL) 標籤的文章。 顯示所有文章
顯示具有 Map (STL) 標籤的文章。 顯示所有文章

2014年8月1日 星期五

LeetCode OJ - Longest Consecutive Sequence (C++) (try 15 times)

為了練習尋找實習時會碰到的問題,我用別人推薦的 LeetCode online judge。
希望能直接寫程式,不用事先編譯就能直接AC。
這是下面是我寫的Longest Consecutive Sequence 的解法。

To practice future interview question, I use LeetCode online judge.
I am trying to type code directly on website without compile in other tool.
The following program is my Longest Consecutive Sequence solution.

2014年5月24日 星期六

LeetCode OJ - Single Number (C++) (try 1 time)

為了練習尋找實習時會碰到的問題,我用別人推薦的 LeetCode online judge。
希望能直接寫程式,不用事先編譯就能直接AC。
這是下面是我寫的  Single Number 的解法。
這篇是舊版本,請看這個改良後的版本。

To practice future interview question, I use LeetCode online judge.
I am trying to type code directly on website without compile in other tool.
The following program is my Single Number solution.
This article is a improved version. See the improved version here.

2014年3月2日 星期日

NTHU OJ - 1003 OTAKU

The following program is my ACcepted code for NTHU-7488.
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know.  :D

此乃NTHU 7488 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )

點這裡看題目 Click here to see this Problem!

我認為也可使用暴力單純一個個搜尋 (時間限制是10秒)
但是我是使用map的簡單應用AC
我之前習慣使用 (m[tmpStr] != 0) 來代表之前沒有存入 map 中的 key 值
但可能因為 map 之前沒有 access 過這個key值,所以 NTHU OJ把這種狀況視為 Runtime Error(SIGABRT).
改成 if(m.count(tmpStr) > 0) 即可AC

I think using brute force to search the key is still fine. (time limit: 10 s)
But I use simple STL map to solve it.
I used to apply (m[tmpStr] != 0) to represent the key, which was not saved in map.
But maybe map didn't access this key value so NTHU OJ think that's Runtime Error(SIGABRT).
I modifed it to if(m.count(tmpStr) > 0) and got AC.

2014年2月25日 星期二

UVa OJ - 353 Pesky Palindromes

The following program is my ACcepted code for UVA-353.
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know.  :D

此乃UAV 353 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )

//This program is for UVA 353 Pesky Palindromes
//http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=289