鏁版嵁缁撴瀯瀹為獙涔嬫爤涓庨槦鍒楀崄涓€锛歳efresh鐨勫仠杞﹀満
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鏁版嵁缁撴瀯瀹為獙涔嬫爤涓庨槦鍒楀崄涓€锛歳efresh鐨勫仠杞﹀満相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/ops' title='ops'>ops
add pre 鍚﹀垯 har 瀹归噺 type tac 鏁版嵁Problem Description
refresh鏈€杩戝彂浜嗕竴绗旀í璐紝寮€浜嗕竴瀹跺仠杞﹀満銆傜敱浜庡湡鍦版湁闄愶紝鍋滆溅鍦哄唴鍋滆溅鏁伴噺鏈夐檺锛屼絾鏄姹傝繘鍋滆溅鍦虹殑杞﹁締杩囧銆傚綋鍋滆溅鍦烘弧鏃讹紝瑕佽繘鍏ョ殑杞﹁締浼氳繘鍏ヤ究閬撶瓑寰咃紝鏈€鍏堣繘鍏ヤ究閬撶殑杞﹁締浼氫紭鍏?/span>
杩涘叆鍋滆溅鍦猴紝鑰屼笖鍋滆溅鍦虹殑缁撴瀯瑕佹眰鍙嚭鍘荤殑杞﹁締蹇呴』鏄仠杞﹀満涓渶鍚庤繘鍘荤殑杞﹁締銆傜幇鍛婅瘔浣犲仠杞﹀満瀹归噺N浠ュ強鍛戒护鏁癕锛屼互鍙婁竴浜涘懡浠わ紙Add num 琛ㄧず杞︾墝鍙蜂负num鐨勮溅杈嗚杩涘叆鍋滆溅鍦烘垨渚块亾锛?/span>
Del 琛ㄧず鍋滆溅鍦轰腑鍑哄幓浜嗕竴杈嗚溅锛孫ut 琛ㄧず渚块亾鏈€鍓嶉潰鐨勮溅杈嗕笉鍐嶇瓑寰咃紝鏀惧純杩涘叆鍋滆溅鍦猴級銆傚亣璁句究閬撳唴鐨勮溅杈嗕笉瓒呰繃1000000.
Input
杈撳叆涓哄缁勬暟鎹紝姣忕粍鏁版嵁棣栧厛杈撳叆N鍜孧锛?锛溿€€锝庯紝锝嶃€€锛?00000锛夛紝鎺ヤ笅鏉ヨ緭鍏鏉″懡浠ゃ€?/span>
Output
杈撳叆缁撴潫鍚庯紝濡傛灉鍑虹幇鍋滆溅鍦哄唴鏃犺溅杈嗚€屽嚭鐜癉el鎴栬€呬究閬撳唴鏃犺溅杈嗚€屽嚭鐜癘ut,鍒欒緭鍑篍rror,鍚﹀垯杈撳嚭鍋滆溅鍦哄唴鐨勮溅杈嗭紝鏈€鍚庤繘鍏ョ殑鏈€鍏堣緭鍑猴紝鏃犺溅杈嗕笉杈撳嚭銆?/span>
Sample Input
2 6
Add 18353364208
Add 18353365550
Add 18353365558
Add 18353365559
Del
Out
Sample Output
18353365558
18353364208
Hint
Source
娉細鍘熸潵鍋氱殑鏃跺€欙紝鏍堟病鏈夌敤base鎸囬拡锛屼竴鐩撮敊璇紝杩樻病鏈夋壘鍒板嚭鐜伴棶棰樼殑鍘熷洜
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5
6 typedef struct node
7 {
8 char num[25];
9 struct node *next;
10 } Node;
11
12 typedef struct
13 {
14 Node *top;
15 Node *base;
16 int len;
17 } SeqStack;
18
19 typedef struct
20 {
21 Node *front;
22 Node *rear;
23 int len;
24 } SeqQueue;
25
26 Node* NewNode()
27 {
28 Node *p;
29 p = (Node*)malloc(sizeof(Node));
30 p->next = NULL;
31 return p;
32 }
33
34 // 鎺ヤ笅鏉ユ槸瀵规爤鐨勬搷浣?/span>
35
36 SeqStack* CreateStack()
37 {
38 SeqStack *t;
39 t = (SeqStack*)malloc(sizeof(SeqStack));
40 t ->top =NewNode();
41 t->base = t->top;
42 t->len = 0;
43 return t;
44 }
45
46 int IsEmptyS(SeqStack *s)
47 {
48 if (s->top->next == NULL)
49 return 1;
50 return 0;
51 }
52
53 void PushS(SeqStack *s, char num[])
54 {
55 Node *p = NewNode();
56 strcpy(p->num,num);
57 p->next = s->top->next;
58 s->top->next = p;
59 s->base = p;
60 s->len++;
61 }
62
63 void PopS(SeqStack *s)
64 {
65 Node *t;
66 t = s->top->next;
67 s->top->next = s->top->next->next;
68 free(t);
69 s->len--;
70 }
71
72 void ClearS(SeqStack* s)
73 {
74 while(!IsEmptyS(s))
75 {
76 PopS(s);
77 }
78 }
79 // 鎺ヤ笅鏉ユ槸瀵归槦鍒楃殑鎿嶄綔
80
81 SeqQueue* CreateQueue()
82 {
83 SeqQueue *q;
84 q = (SeqQueue*)malloc(sizeof(SeqQueue));
85 q->front = NewNode();
86 q->rear = q->front;
87 q->len = 0;
88 return q;
89 }
90
91 int IsEmptyQ(SeqQueue *q)
92 {
93 if (q->front->next == NULL)
94 return 1;
95 return 0;
96 }
97
98 void PushQ(SeqQueue *q, char num[])
99 {
100 Node *t = NewNode();
101 strcpy(t->num, num);
102 q->rear->next = t;
103 q->rear = t;
104 q->len++;
105 }
106
107 void PopQ(SeqQueue *q)
108 {
109 Node *t = q->front->nexxt;
110 q->front->next = q->front->next->next;
111 free(t);
112 q->len--;
113 }
114
115 void show(Node *t)
116 {
117 Node *p = t->next;
118 while(p)
119 {
120 printf("%s
", p->num);
121 p = p->next;
122 }
123 }
124
125 void ClearQ(SeqQueue *q)
126 {
127 if(!IsEmptyQ(q))
128 {
129 PopQ(q);
130 }
131 }
132
133 int main()
134 {
135 int n, m;
136 char str[25];
137 char num[25];
138 SeqQueue *q;
139 SeqStack *s;
140 s = CreateStack();
141 q = CreateQueue();
142 while(~scanf("%d%d", &n, &m))
143 {
144 int flag = 1;
145 ClearS(s);
146 ClearQ(q);
147 while(m--)
148 {
149 scanf("%s", str);
150 if (strcmp(str, "Add") == 0) // 濡傛灉鏍堟病婊★紝鍏ユ爤锛屽惁鍒欏叆闃?/span>
151 {
152 scanf("%s", num);
153 if (s->len >= n)
154 {
155 PushQ(q, num);
156 }
157 else
158 {
159 PushS(s, num);
160 }
161 }
162 else if (strcmp(str, "Del") == 0) // 濡傛灉鏍堟病绌猴紝鍒欏嚭鏍堬紝鍚屾椂鍚庨潰鐨勮溅鍑洪槦鍏ユ爤
163 {
164 if (!IsEmptyS(s))
165 {
166 PopS(s);
167 if (!IsEmptyQ(q))
168 {
169 strcpy(num,q->front->next->num);
170 PopQ(q);
171 PushS(s, num);
172 }
173 }
174 else
175 {
176 flag = 0;
177 }
178 }
179 else if (strcmp(str, "Out") == 0) // 涓嶆帓闃燂紝鍑洪槦
180 {
181 if (!IsEmptyQ(q))
182 {
183 PopQ(q);
184 }
185 else
186 {
187 flag = 0;
188 }
189 }
190 }
191 if (flag == 0)
192 {
193 printf("Error
");
194 }
195 else
196 {
197 show(s->top);
198 }
199 }
200 return 0;
201 }
以上是关于鏁版嵁缁撴瀯瀹為獙涔嬫爤涓庨槦鍒楀崄涓€锛歳efresh鐨勫仠杞﹀満的主要内容,如果未能解决你的问题,请参考以下文章