作者rod24574575 (天然呆)
看板b99902HW
標題[作業] 計程單班Homework「Double palindrome」
時間Tue Sep 28 23:56:05 2010
有強者能分享一下大略的思考或解題方向嗎??
想了很久還是不知道該從哪裡下手才好= =+
題目附在下面
雙班的強者也可以看看XD
--
Double palindrome
We define a palindrome as a sequence of at least one integer that reads the
same either forward or backward. For example "1 3 5 3 1" and "1 2 2 1" are
both palindromes. To the extreme case "1" is also a palindrome.
We also define a double palindrome as the concatenation of two palindromes.
For example "1 3 5 3 1 1 2 2 1" is a double palindrome. To the extreme case
"1 3 5 3 1 1" is also a double palindromes.
Now given a sequence of at least two integers, please find the longest double
palindrome. If there are multiple longest double palindromes, print the one
that appears last.
The number of intergers in the given sequence is no more than 100.
Sample Input
7 1 3 5 3 1 1
Sample Output
1 3 5 3 1 1
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.167.184.2
1F:推 PttHobe:首先呢要能夠先想到找到單個回文的辦法 09/29 00:20
2F:推 a13032002:找到所有盡量長的單回文,並且記錄開始的位子、結束的 09/29 01:18
3F:→ a13032002:位子及回文長度,再找出其中兩個相鄰(其中一個結束位子 09/29 01:21
4F:→ a13032002:+1=另一個的開始位子)且長度最大的回文 09/29 01:23
5F:→ a13032002:合起來就是答案XXD,但這只是一個對於長度最多100的數列 09/29 01:27
6F:→ a13032002:不太溫柔的解法XXD 09/29 01:27
※ 編輯: rod24574575 來自: 218.167.184.2 (09/29 03:10)
7F:→ rod24574575:試了好久送出去還是只有5分 Orz 09/29 03:11
8F:→ arthur104:要怎知道read幾個數字阿@@ 09/29 16:08
9F:推 Kitsching:我跟樓上有一樣的問題 09/29 18:58
10F:推 m80126colin:第一行讀入N代表接下來有N個數字?? 09/29 20:15
11F:→ m80126colin:不好意思我搞錯了....... 09/29 20:15
12F:→ bill8124:scanf函數值為1是有讀到東西 計程課下課後有提到 09/29 20:56
13F:推 garychou:我是先用第一個與其他個比較 如果有相同則夾擊比對 09/29 20:59
14F:→ garychou:比對方式與氣泡排序法的比對方式相同 用for裡面在一個for 09/29 21:01
15F:→ garychou:最後紀錄每種雙回文的頭跟尾的index 如果頭跟尾差比較大 09/29 21:04
16F:→ garychou:就覆蓋比較小的值 如此一來就能找到最長雙回文頭跟尾了 09/29 21:06
17F:推 garychou:while(scanf()!=-1){} 回傳-1代表EOF 而自己輸入測資時 09/29 21:09
18F:→ garychou:輸入完按ctrl+z就可以跑得動了 或是存成txt檔以<匯入程式 09/29 21:12
19F:→ bill8124:感謝garychou 其實我也是一知半解 09/29 21:15
20F:推 garychou:其實我是輸入資料之後不知道如何停止輸入 問強者得知的 09/29 22:38
21F:→ PttHobe:是誰教用 !=-1 的啊 用 == 1 比較健康 09/30 15:46
22F:推 m80126colin:會有跑出1跟-1以外的情況???? 09/30 19:11
23F:推 s864372002:不符格式的輸入就可能會有0啦,雖然在judge裡應該不會 09/30 21:27
24F:推 garychou:呃 !=-1是我想的XD ctrl+z是問強者的XD 09/30 23:35
25F:推 flyingmars:輸入EOF呢? 10/01 01:02
26F:→ rod24574575:輸入eof就代表你的輸入完畢了 10/01 01:06
27F:推 flyingmars:我的意思是丟入上述情況的scanf中會是-1 還是 0 ? 10/01 01:07
28F:→ flyingmars:是零 所以程式把他當做一般英文字處理的意思.... 10/01 01:17
29F:推 s864372002:EOF沒辦法「輸入」,它是一個狀態,當scanf()偵測到檔 10/01 09:00
30F:→ s864372002:尾或異常終止(由^z製造出來)時,會回報這個狀態,而 10/01 09:00
31F:→ s864372002:在stdio.h裡面 EOF 這個詞被define成-1,很多輸入函數 10/01 09:02
32F:→ s864372002:都是回傳-1代表這個狀態(gets()/fgets()除外) 10/01 09:02