关注
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
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 你的mentor是什么样的人? #
9838次浏览 80人参与
# 毕业租房也有小确幸 #
140002次浏览 4488人参与
# 平安产险科技校招 #
2568次浏览 0人参与
# 帮我看看,领导说这话什么意思? #
12229次浏览 73人参与
# 牛友的志愿填报指南 #
33096次浏览 173人参与
# 怎么给家人解释你的工作? #
5722次浏览 46人参与
# 未岚大陆求职进展汇总 #
38832次浏览 121人参与
# 得物app工作体验 #
26687次浏览 58人参与
# 租房前辈的忠告 #
258743次浏览 7112人参与
# 求职低谷期你是怎么度过的 #
8988次浏览 170人参与
# 26届秋招公司红黑榜 #
21605次浏览 77人参与
# 你觉得mentor喜欢什么样的实习生 #
14193次浏览 375人参与
# 校招泡的最久的公司是哪家? #
8895次浏览 53人参与
# 国企还是互联网,你怎么选? #
166570次浏览 1151人参与
# 求职中的尴尬瞬间 #
1000次浏览 17人参与
# 从哪些方向判断这个offer值不值得去? #
10334次浏览 117人参与
# 度小满求职进展汇总 #
11554次浏览 61人参与
# 没有家庭托举的我是怎么找工作的 #
16635次浏览 200人参与
# 牛客树洞,我想对你说 #
3439次浏览 58人参与
# 实习必须要去大厂吗? #
148871次浏览 1551人参与
# 关于求职,我有X不投 #
39376次浏览 214人参与
# 你怀疑过自己的专业选择吗? #
24600次浏览 206人参与