File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ #include <stdlib.h>
3+
4+ typedef struct SQ {
5+ int data ;
6+ struct SQ * link ;
7+ }SQ ;
8+
9+ SQ * TAIL ;
10+
11+ int isEmpty () {
12+ if (TAIL == NULL ) return 1 ;
13+ else return 0 ;
14+ }
15+
16+ void Push (int seq ) {
17+ SQ * tmp = (SQ * )malloc (sizeof (SQ ));
18+ tmp -> data = seq ;
19+ tmp -> link = TAIL ;
20+ TAIL = tmp ;
21+ }
22+
23+ int Pop () {
24+ int pData ;
25+ SQ * popT = TAIL ;
26+ if (TAIL == NULL ) return 0 ;
27+ else {
28+ pData = popT -> data ;
29+ TAIL = popT -> link ;
30+ free (popT );
31+ return pData ;
32+ }
33+ }
34+
35+ int top () {
36+ if (TAIL == NULL ) return 0 ;
37+ else return TAIL -> data ;
38+ }
39+ int main () {
40+ int n ,s = 0 ,i ,j = 0 ;
41+ scanf ("%d" , & n );
42+ char * print = (char * )malloc (sizeof (char )* 2 * n );
43+ int * Seq = (int * )malloc (sizeof (int )* n );
44+
45+ for (i = 0 ; i < n ; i ++ ) {
46+ scanf ("%d" ,& Seq [i ]);
47+ }
48+ for (i = 1 ; i <= n ; i ++ ) {
49+ Push (i );
50+ print [s ++ ] = '+' ;
51+ while (!isEmpty () && top () == Seq [j ]) {
52+ Pop ();
53+ print [s ++ ] = '-' ;
54+ j ++ ;
55+ }
56+ }
57+ if (!isEmpty ()) printf ("NO" );
58+ else {
59+ for (i = 0 ; i < 2 * n ; i ++ ) {
60+ printf ("%c\n" , print [i ]);
61+ }
62+ }
63+ return 0 ;
64+ }
Original file line number Diff line number Diff line change 1+ | 제출 번호| 아이디| 문제| 결과| 메모리| 시간| 언어| 코드길이|
2+ | :---| :---| :---| :---| :---| :---| :---| :---|
3+ | 27036089| jjongmin77| 1874| 맞았습니다!!| 2232KB| 32ms| C++17| 958B|
You can’t perform that action at this time.
0 commit comments