关注
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
相关推荐
06-26 22:13
华北理工大学 人力资源专员/助理 
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 哪些公司开提前批了? #
23522次浏览 251人参与
# 你今年的平均薪资是多少? #
133757次浏览 682人参与
# 风评不好的公司,你会去吗? #
56166次浏览 400人参与
# 实习如何「偷」产出? #
47306次浏览 1234人参与
# 除了主业以外,你还有哪些其他收入? #
10998次浏览 193人参与
# 互联网公司评价 #
400964次浏览 3836人参与
# 你最满意的offer薪资是哪家公司? #
32922次浏览 176人参与
# 节后第一天上班,我的精神状态 #
13348次浏览 117人参与
# 不卡学历的大厂有哪些? #
26352次浏览 212人参与
# 校招阶段,学历VS技术哪个更重要? #
16292次浏览 182人参与
# 职场新人体验 #
22832次浏览 223人参与
# 签约/解约注意事项 #
696708次浏览 4068人参与
# 腾讯音乐求职进展汇总 #
97941次浏览 570人参与
# 你投递的公司有几家约面了? #
108693次浏览 777人参与
# 校园里的破防时刻 #
10237次浏览 117人参与
# 正在实习的碎碎念 #
1454023次浏览 13469人参与
# 硬件人求职现状 #
434321次浏览 4539人参与
# 实习打杂,要跑路吗 #
17462次浏览 201人参与
# 宁德时代求职进展汇总 #
122639次浏览 650人参与
# Offer比较,你最看重什么? #
191393次浏览 1301人参与