关注
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
相关推荐
07-20 21:58
门头沟学院 嵌入式软件开发 点赞 评论 收藏
分享
sagima:面这么久说明面试官确实认可你,去年我面滴滴20分钟直接挂
点赞 评论 收藏
分享
sounfury:找java工作的话把java内容占比写多点,你鸿蒙写太多了
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 哪些公司开提前批了? #
13857次浏览 176人参与
# 实习如何「偷」产出? #
35895次浏览 785人参与
# 校招阶段,学历VS技术哪个更重要? #
12642次浏览 157人参与
# 除了主业以外,你还有哪些其他收入? #
8227次浏览 152人参与
# 不卡学历的大厂有哪些? #
19996次浏览 152人参与
# Offer比较,你最看重什么? #
190721次浏览 1297人参与
# 风评不好的公司,你会去吗? #
47959次浏览 355人参与
# 实习打杂,要跑路吗 #
14731次浏览 189人参与
# 职场新人体验 #
17242次浏览 172人参与
# 腾讯音乐求职进展汇总 #
97411次浏览 566人参与
# 校园里的破防时刻 #
8196次浏览 95人参与
# 社恐入职新公司如何融入团队 #
11185次浏览 62人参与
# 实习时,大家都怎么称呼自己的mentor? #
43336次浏览 273人参与
# 面试中,你被问过哪些奇葩问题? #
70325次浏览 802人参与
# 摸鱼被leader发现了怎么办 #
60883次浏览 371人参与
# 双非能在秋招上岸吗? #
226502次浏览 1215人参与
# 非技术投递记录 #
611258次浏览 6413人参与
# 金融财经春招备战日记 #
22929次浏览 135人参与
# 考研可以缓解求职焦虑吗 #
53669次浏览 474人参与
# 正在实习的碎碎念 #
1452634次浏览 13464人参与