Re: ((一))
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









--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.68.213
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1488475451.A.ADE.html
噓
03/03 01:25, , 1F
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
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
03/03 01:34, 10F
→
03/03 01:40, , 11F
03/03 01:40, 11F
推
03/03 01:47, , 12F
03/03 01:47, 12F
討論串 (同標題文章)