跳至內容
台州語維基百科
使用者工具
登入
網站工具
搜尋
工具
顯示頁面
舊版
反向連結
新建頁面
新建目錄
最近更新
多媒體管理器
網站地圖
登入
>
最近更新
多媒體管理器
網站地圖
足跡:
codes
本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。
===== 栈 ===== <code> #include <iostream> #include <stack> using namespace std; string change(int n) { stack<int> s; while(n>0) { s.push(n%2); n/=2; } string m=""; // while(!s.empty()) // { // m+=to_string(s.top()); // s.pop(); // } for(int i=s.size(); i>0; --i) { m += to_string(s.top()); s.pop(); } return m; } int main() { int num; cin >> num; string s=change(num); cout << s; } </code> ===== 栈的使用[](){} ===== <code> #include <iostream> #include <stack> using namespace std; char change(char n) { if(n==')') return '('; if(n==']') return '['; if(n=='}') return '{'; } int main() { stack<char> s; string p; cin >> p; for(int i=0; i<p.size(); ++i) { if(s.empty()) { s.push(p[i]); continue; } else if(change(p[i]) == s.top()) { s.pop(); } else { s.push(p[i]); } } if(s.empty()) printf("Yes"); else printf("No"); } </code> ===== 队列 ===== <code> #include <iostream> #include <queue> using namespace std; int main() { int n, m; cin >> n >> m; queue<int> q; for(int i=1; i<=n; ++i) { q.push(i); } while(!q.empty()) { for(int i=1; i<m; ++i) { q.push(q.front()); q.pop(); } cout << q.front() << " "; q.pop(); } cout << endl; } </code>
codes.txt
· 上一次變更:
2025/12/18 10:18
由
benojan
頁面工具
顯示頁面
舊版
反向連結
新建頁面
新建目錄
回到頁頂