关注
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
相关推荐
说又不是不能用的:之前也想回老家,结果发现除了考公和靠关系的工作,根本没适合的岗位,省会合肥的竞争比北上广还卷,最后还是认清现实:普通人想赚钱,只能去大城市😭 点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 那些年,我收到的‘奇葩’回复 #
19230次浏览 148人参与
# 实习需要主动找活干吗? #
54219次浏览 291人参与
# 小红书开奖了 #
30952次浏览 153人参与
# OC/开奖 #
186437次浏览 1310人参与
# 秋招你经历过哪些无语的事 #
19738次浏览 230人参与
# 职场中那些令人叹为观止的八卦 #
28359次浏览 238人参与
# 腾讯音乐秋招 #
429931次浏览 4774人参与
# 秋招吐槽大会 #
85306次浏览 744人参与
# 蚂蚁求职进展汇总 #
130665次浏览 1200人参与
# 校招薪资来揭秘 #
75011次浏览 483人参与
# 实习教会我的事 #
41317次浏览 340人参与
# 你找工作想离家近 or 离家远? #
15802次浏览 235人参与
# 我的职场社死时刻 #
20795次浏览 165人参与
# 你秋招最后悔的选择 #
16249次浏览 122人参与
# 租房前辈的忠告 #
289731次浏览 7267人参与
# 材料人,你最希望上岸的是? #
10930次浏览 56人参与
# 2022毕业即失业取暖地 #
119610次浏览 709人参与
# 哪些公司开始补录了 #
20374次浏览 162人参与
# AI时代,哪些岗位最容易被淘汰 #
10656次浏览 87人参与
# XX请雇我工作 #
14969次浏览 113人参与
# 小马智行求职进展汇总 #
17135次浏览 54人参与
# 扒一扒那些奇葩实习经历 #
131115次浏览 1123人参与
