关注
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
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 给工作过的公司写一条大众点评,你会怎么写? #
1136次浏览 23人参与
# 牛油的搬砖plog #
189276次浏览 1272人参与
# 厦门银行科技岗值不值得投 #
16578次浏览 404人参与
# 烂工作和没工作哪个更痛苦? #
1699次浏览 46人参与
# 发工资后,你做的第一件事是什么 #
100315次浏览 336人参与
# AI替代不了什么? #
1682次浏览 39人参与
# 学历VS实习,哪个更重要? #
10063次浏览 157人参与
# 一人分享一道面试手撕题 #
114085次浏览 2872人参与
# 工作上你捅过哪些篓子? #
69265次浏览 334人参与
# 产品人求职现状 #
361335次浏览 2603人参与
# 谈薪时HR压价该怎么应对 #
294076次浏览 3361人参与
# 春招至今,你收到几个面试了? #
4167次浏览 43人参与
# 机械校招之路总结 #
120285次浏览 2083人参与
# 面试紧张时你会有什么表现? #
35757次浏览 243人参与
# 刚工作的你,踩过哪些坑? #
33330次浏览 278人参与
# uu们,春招你还来吗? #
69696次浏览 929人参与
# 面试中,你被问过哪些奇葩问题? #
99450次浏览 1429人参与
# 非技术投递记录 #
716827次浏览 6930人参与
# 你的实习什么时候入职 #
368219次浏览 2368人参与
# 牛友的志愿填报指南 #
63926次浏览 492人参与
# 实习生应该准时下班吗 #
349243次浏览 1752人参与
