標題:
[作業繳交] 2025/03/29
[打印本頁]
作者:
方浩葦
時間:
2025-3-29 03:49
標題:
[作業繳交] 2025/03/29
本帖最後由 方浩葦 於 2025-3-29 14:58 編輯
1.『基礎題庫』- a045
2. APCS 觀念題 (考古題):10510 - 13、14
作者:
黃暐鈞
時間:
2025-3-29 13:43
https://blog.csdn.net/weixin_55037029/article/details/118811206
作者:
江家同
時間:
2025-4-12 11:43
1.『基礎題庫』- a045
#include<bits/stdc++.h>
#include<stack>
using namespace std;
bool isbracket(string c)
{
stack<char>s;
for(int i=0;i<c.size();i++)
{
if(c[i]=='['||c[i]=='('||c[i]=='{')
{
s.push(c[i]);
}
else if(c[i]==']'||c[i]==')'||c[i]=='}')
{
if(s.empty()||
(c[i]=='}'&&s.top()!='{')||
(c[i]==']'&&s.top()!='[')||
(c[i]==')'&&s.top()!='('))
return false;
s.pop();
}
}
return s.empty();
}
int main()
{
string line;
int count=0;
while(getline(cin,line)&& count<20)
{
if(line.empty())break;
if(line.size()>150)continue;
cout<<(isbracket(line)?"yes":"no")<<'\n';
count++;
}
return 0;
}
複製代碼
2. APCS 觀念題 (考古題):
10510 - 13
(C)
複製代碼
10510 - 14
(A)
複製代碼
作者:
許浩浩
時間:
2025-4-12 12:46
本帖最後由 許浩浩 於 2025-4-12 14:16 編輯
1.『基礎題庫』- a045
#include<bits/stdc++.h>
using namespace std;
bool n(string c)
{
stack<char> s;
for(int i=0;i<c.length();i++)
{
if(c[i]=='(' or c[i]=='[' or c[i]=='{')
s.push(c[i]);
else if(s.empty()){
return false;
}
else if((s.top()=='(' and c[i]==')')or(s.top()=='[' and c[i]==']')or(s.top()=='{' and c[i]=='}'))
s.pop();
}
return s.empty();
}
int main()
{
cin.tie(0);
cin.sync_with_stdio(0);
string line;
int count=0;
while(cin>>line and count<20)
{
if(line.empty())
break;
if(line.length()>150)
continue;
if(n(line))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
count++;
}
return 0;
}
複製代碼
2. APCS 觀念題 (考古題):10510 - 13、14
(B)(A)
複製代碼
作者:
郭博鈞
時間:
2025-4-12 13:15
1.『基礎題庫』- a045
#include<bits/stdc++.h>
using namespace std;
bool B(string c)
{
stack<char> a;
for(int i=0;i<c.length();i++)
{
if(c[i]=='{' or c[i]=='[' or c[i]=='(')
{
a.push(c[i]);
}
else if(c[i]=='}' or c[i]==']' or c[i]==')')
{
if(a.empty() or (c[i]=='}' and a.top() != '{') or
(c[i] == ']' and a.top() != '[') or
(c[i]==')' and a.top() != '('))
{
return false;
}
a.pop();
}
}
return a.empty();
}
int main()
{
string line;
int count=0;
while(getline(cin,line) and count<20)
{
if(line.empty())
{
break;
}
if(line.length()>150)
{
continue;
}
cout<<(B(line) ? "yes":"no")<<'\n';
count++;
}
return 0;
}
複製代碼
2. APCS 觀念題 (考古題):10510 - 13、14
C
A
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://www.istak.org.tw/seed/)
Powered by Discuz! 7.2