作者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