codility] Nesting
1.풀이
-이전에 풀었던 Brackets와 동일.
2.소스
https://app.codility.com/demo/results/trainingRSB8GS-M67/
#include <algorithm> #include <stack> #include <string.h> // you can write to stdout for debugging purposes, e.g. // cout << "this is a debug message" << endl; int solution(string &S) { // write your code in C++14 (g++ 6.2.0) stack<int> stack; //stack.push(); //stack.pop(); //stack.top(); for(unsigned int i=0; i < S.length(); i++) { if(S[i] == '(') stack.push(99); else { if(!stack.empty()) { stack.pop(); } else { return 0; } } } if(!stack.empty()) return 0; return 1; }