luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/PTIT015 #813

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Chi tiết bài tập - Luyện Code Online

https://oj.luyencode.net/problem/PTIT015

Conan286 commented 2 years ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

https://github.com/huycn9/c-cpp-basic/blob/main/PTIT015%20-%20Li%E1%BB%87t%20k%C3%AA%20d%C3%A3y%20ngo%E1%BA%B7c%20%C4%91%C3%BAng.cpp

buichivi commented 1 year ago

Đây là lời giải của mình đã AC ai chưa làm được có thể tham khảo.

Xem code C++ ```cpp #include using namespace std; #define ll long long int N, cnt = 0; char X[100]; bool Check() { stack st; for (int i=1; i<=N; i++) { if (X[i] == '(') st.push(X[i]); if (X[i] == ')') { if (!st.empty()) { st.pop(); } else return false; } } if (st.empty()) return true; return false; } void inkq() { for (int i=1; i<=N; i++) cout << X[i]; cout << "\n"; } void Try(int i) { if (i > N) { if (Check()) { inkq(); cnt++; } return; } X[i] = '('; Try(i+1); X[i] = ')'; Try(i+1); } void solve() { cin >> N; Try(1); cout << cnt; } int main() { solve(); return 0; } ```