Zoj 1405Tanning Salon {4933}
The number of beds in a room is given, indicating in alphabetical order of all guests. If there is no bed, the guests will leave and ask the number of guests to leave.
Train of Thought: When a guest arrives, he will not leave without a bed immediately. He will not leave as long as the bed is empty before he leaves. For details, seeCode.
Code:
# Include <stdio. h> int main () {int I, J, K, C, F, N, V, G; char a [30], B [30], h; for (I = 1; I ++) {scanf ("% d", & N); If (n = 0) break; getchar (); G = 0; f = 0; C = 0; For (j = 0; j ++) {v = 0; H = getchar (); if (H <'A' | h> 'Z') break; For (k = 0; k <= F-1; k ++) {// guests who have used the bed are leaving. If (H = A [k]) {v = 1; n ++; break ;}} if (n = 0) {for (k = 0; k <= g-1; k ++) {// guests who have never used a bed should leave. If (H = B [k]) {C ++; V = 1; break ;}} if (V = 0) {// no bed is waiting for the guests who have not left. B [g] = H; G ++ ;}} if (n> 0 & V = 0) {// guests with a bed will arrive immediately. A [f] = H; F ++; n -- ;}} if (C = 0) printf ("All MERs tanned successfully. \ n "); elseprintf (" % d customer (s) lost ed away. \ n ", c);} return 0 ;}