关注
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
相关推荐
点赞 评论 收藏
分享
01-03 14:09
成都信息工程大学 Java 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 在大厂上班是一种什么样的体验 #
9532次浏览 123人参与
# 为了减少AI幻觉,你注入过哪些设定? #
3813次浏览 130人参与
# 程序员找工作至少要刷多少题? #
16535次浏览 231人参与
# 机械人避雷的岗位/公司 #
42983次浏览 289人参与
# 我现在比当时_,你想录用我吗 #
8193次浏览 108人参与
# 你认为工作的意义是什么 #
248908次浏览 1496人参与
# 一张图晒一下你的AI员工 #
4616次浏览 111人参与
# 论秋招对个人心气的改变 #
9681次浏览 151人参与
# AI Coding的使用心得 #
4234次浏览 99人参与
# 刚入职的你踩过哪些坑 #
6296次浏览 125人参与
# 关于春招/暑期实习,你想知道哪些信息? #
6904次浏览 116人参与
# 牛客AI体验站 #
6046次浏览 167人参与
# 晒晒你司的新年福利 #
7621次浏览 100人参与
# 12306一秒售罄,你抢到回家的票了吗? #
1750次浏览 46人参与
# 程序员能干到多少岁? #
8047次浏览 113人参与
# 你认为小厂实习有用吗? #
117880次浏览 679人参与
# 总结:哪家公司面试体验感最差 #
92793次浏览 429人参与
# 应届生进小公司有什么影响吗 #
118137次浏览 1158人参与
# 找工作的破防时刻 #
253768次浏览 1963人参与
# 找工作时的取与舍 #
119722次浏览 867人参与
