Http://acm.nyist.net/JudgeOnline/problem.php? PID = 2
1. MyCode:
# Include <iostream> # include <cstring> using namespace STD; # define maxsize 10005int main (void) {int K; CIN> K; while (k --) {char STR [maxsize]; CIN> STR; char stack [maxsize]; int Len = strlen (STR); Int J = 0; bool tag = true; for (INT I = 0; I <Len; I ++) {Switch (STR [I]) {Case '(': Case '[': stack [J ++] = STR [I]; break; Case ')': If (stack [J-1] = '(') {tag = true; J --;} else tag = false; break; Case ']': If (Stack [J-1] = '[') {tag = true; j --;} else tag = false; break; default: cout <"error! "<Endl;} If (TAG = false) // notebreak;} If (TAG = true & J = 0) cout <"yes" <Endl; elsecout <"no" <Endl;} return 0 ;}
2. Optimal code for time, memory, and length:
# Include <stdio. h> int main () {int t; char C, S [10001], * P; scanf ("% d \ n", & T); While (t --) {* s = getchar (); P = S + 1; while (C = getchar ())! = '\ N') {If (* (p-1) = C-1 | * (p-1) = C-2) p --; else * P ++ = C ;} if (P = s) printf ("Yes \ n"); elseprintf ("NO \ n ");}}
3. Bidding Process:
# Include <iostream> # include <vector> # include <string> using namespace STD; int main () {int N; CIN> N; while (n --) {vector <char> VEC; string ch; Vec. push_back (''); CIN> CH; For (INT I = 0; I <ch. length (); I ++) {Vec. push_back (CH [I]); If (VEC. back ()-1 = * (VEC. end ()-2) | Vec. back ()-2 = * (VEC. end ()-2) {Vec. pop_back (); Vec. pop_back () ;}} if (VEC. size () = 1) cout <"yes" <Endl; elsecout <"no" <Endl;} return 0 ;}
(I always use the stack code to submit wa. I don't know why, see
Http://blog.csdn.net/justme0/article/details/7415337)