关注
1 字符串a<<b() int main() {
string str;
cin>>str;
stack<char> s;
for(int i=0;i<str.length();i++){
if(str[i]==')'){
while(s.top()!='(')
s.pop();
s.pop();
} else
s.push(str[i]);
}
string tmp;
int cnt=0;
while(!s.empty()){
char temp=s.top();
if(temp=='<')
cnt++;
else{
if(cnt==0){
tmp+=s.top();
}
cnt--;
cnt=max(0,cnt);
}
s.pop();
}
string t;
for(int i=tmp.length()-1;i>=0;i--){
cout<<tmp[i];
}
cout<<endl;
return 0;
} 2 迷宫题 #include<bits/stdc++.h>
using namespace std;
const int N=105;
int n;
int start_x=0;
int start_y=0;
char mat[N][N];
int flag[N][N];
struct P{
int x;
int y;
int step;
P(int _x,int _y,int _step){x=_x;y=_y;step=_step;}
};
int minLen=INT32_MAX;
void bfs(){
queue<P*> q;
q.push(new P(start_x,start_y,0));
while(!q.empty()){
P *temp=q.front();
q.pop();
int x=temp->x;
int y=temp->y;
int step=temp->step;
//cout<<x<<" "<<y<<endl;
if(x==-1) x=n-1;
if(y==-1) y=n-1;
if(x==n) x=0;
if(y==n) y=0;
if(mat[x][y]=='E'){
if(step<minLen)
minLen=step;
}
if(flag[x][y]||mat[x][y]=='#')
continue;
flag[x][y]=1;
q.push(new P(x,y+1,step+1));
q.push(new P(x,y-1,step+1));
q.push(new P(x+1,y,step+1));
q.push(new P(x-1,y,step+1));
}
}
int main() {
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>mat[i][j];
if(mat[i][j]=='S'){
start_x=i;
start_y=j;
}
}
}
bfs();
if(minLen==INT32_MAX)
cout<<-1<<endl;
else
cout<<minLen<<endl;
return 0;
}
查看原帖
点赞 1
相关推荐
2025-11-26 10:52
广州理工学院 后端工程师 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 有深度的简历长什么样? #
6619次浏览 133人参与
# 哪些公司在招寒假实习? #
2235次浏览 33人参与
# 去年的flag与今年的小目标 #
2532次浏览 69人参与
# 卷__卷不过你们,只能卷__了 #
1749次浏览 37人参与
# 26年哪些行业会变好/更差 #
3318次浏览 59人参与
# 你都用AI做什么 #
2548次浏览 67人参与
# 实习学到最有价值的工作习惯 #
54087次浏览 433人参与
# 写论文的崩溃时刻 #
1616次浏览 43人参与
# 实习,不懂就问 #
146608次浏览 1302人参与
# 一人分享一道面试手撕题 #
9267次浏览 476人参与
# 入职第一天 #
4512次浏览 52人参与
# 你不能接受的企业文化有哪些 #
3114次浏览 60人参与
# AI了,我在打一种很新的工 #
125641次浏览 1304人参与
# 应届生应该先就业还是先择业 #
161156次浏览 812人参与
# 听到哪句话就代表面试稳了or挂了? #
240645次浏览 1681人参与
# 考研人,我有话说 #
159503次浏览 1225人参与
# 秋招你被哪家公司挂了? #
1000524次浏览 7690人参与
# 你的国庆怎么过 #
109471次浏览 764人参与
# 应届生第一份工作最好去大厂吗? #
124168次浏览 1102人参与
# 面试之前应该如何准备? #
209048次浏览 2306人参与
查看1道真题和解析
上海得物信息集团有限公司公司福利 1260人发布