Re: ((一))

看板Marginalman作者 (酷拉皮卡買醬油)時間8年前 (2017/03/03 01:24), 編輯推噓1(219)
留言12則, 4人參與, 最新討論串2/2 (看更多)
In this problem we consider expressions containing brackets that are properly nested. These expressionsare obtained by juxtaposition of properly netsted expressions in a pair of matching brackets, the leftone an opening and the right one a closing bracket. ( a + $ ( b = ) ( a ) ) is properly nested ( a + $ ) b = ) ( a ( ) is not In this problem we have several pairs of brackets, so we have to impose a second condition on the expression: the matching brackets should be of the same kind. Consequently ‘(())’ is OK, but ‘([))’ is not. The pairs of brackets are: ( ) [ ] { } < > (* *) The two characters ‘(*’ should be interpreted as one symbol, not as an opening bracket ‘(’ followed immediately by an asterisk, and similarly for ‘*)’. The combination ‘(*)’ should be interpreted as ‘(*’followed by ‘)'. Write a program that checks wheter expressions are properly nested. If the expression is not properly nested your program should determine the position of the off ending bracket, that is the length of the shortest prefi x of the expression that can not be extended to a properly nested expression. Don’t forget ‘(*’ counts as one, as does ‘*)’. The characters that are not brackets also count as one. Input The input is a text-file. Each line contains an expression to be checked followed by and end-of-line marker. No line contains more than 3000 characters. The input ends with a standard end-of-fi le marker. Output The output is a textfi le. Each line contains the result of the check of the corresponding inputline, that is ‘YES’ (in upper case), if the expression is OK, and (if it is not OK) ‘NO’ followed by a space and the position of the error. Sample Input (*a++(*) (*a{+}*) Sample Output NO 6 YES -- 我老婆1 http://i.imgur.com/qcvvvGh.png
我老婆2 http://i.imgur.com/H44FJSx.jpg
我老婆3 http://i.imgur.com/6D9pgK5.png
我老婆4 http://i.imgur.com/r0Pv1eb.jpg
我老婆5 http://i.imgur.com/g8in5mO.jpg
我老婆6 http://i.imgur.com/s6GAEQX.png
我老婆7 http://i.imgur.com/vJSjNPg.png
我老婆8 http://i.imgur.com/BPJVHDF.png
我老婆9 http://i.imgur.com/hnmzCi3.png
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.68.213 ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1488475451.A.ADE.html

03/03 01:25, , 1F
這又是那段code
03/03 01:25, 1F

03/03 01:26, , 2F
愛紗你該不會是直接複製貼上了那個題目吧...
03/03 01:26, 2F

03/03 01:26, , 3F
當然複製貼上阿幹 怎麼可能手打
03/03 01:26, 3F

03/03 01:27, , 4F
這題給你5個小時 gogo
03/03 01:27, 4F

03/03 01:28, , 5F
我要睡覺啦姆咪
03/03 01:28, 5F

03/03 01:30, , 6F
稍微看一下,他是叫你檢查括號有沒有成對,如果沒有要
03/03 01:30, 6F

03/03 01:30, , 7F
指出不合理的地方這樣
03/03 01:30, 7F

03/03 01:30, , 8F
03/03 01:30, 8F

03/03 01:33, , 9F
摁摁
03/03 01:33, 9F

03/03 01:34, , 10F
這個我會 用 stack 對ㄅ 對? 其實我沒有看題目
03/03 01:34, 10F

03/03 01:40, , 11F
嘻嘻 這種都stack
03/03 01:40, 11F

03/03 01:47, , 12F
Divide and conquer嗎
03/03 01:47, 12F
文章代碼(AID): #1Ok5KxhU (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1Ok5KxhU (Marginalman)