nowcoder要和朋友交流一些敏感的信息,例如他的电话号码等。因此他要对这些敏感信息进行混淆,比如在数字中间掺入一些额外的符号,让它看起来像一堆乱码。
现在请你帮忙开发一款程序,解析从nowcoder那儿接收到的信息,读取出中间有用的信息。
输入描述:
输入有多行。
每一行有一段经过加密的信息(其中可能包含空格),并且原始信息长度不确定。
输出描述:
输出每段信息中数字信息。
示例1
输入
$ Ts!47&* s456 a23 * + B9k
输出
47456239
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
for(auto e : str)
{
if(e >= '0' && e <= '9')
cout << e;
}
cout << endl;
}
return 0;
}
NowCoder最喜欢游乐场的迷宫游戏,他和小伙伴们比赛谁先走出迷宫。
现在把迷宫的地图给你,你能帮他算出最快走出迷宫需要多少步吗?
输入描述:
输入包含多组数据。
每组数据包含一个10*10,由“#”和“.”组成的迷宫。其中“#”代表墙;“.”代表通路。
入口在第一行第二列;出口在最后一行第九列。
从任意一个“.”点都能一步走到上下左右四个方向的“.”点。
输出描述:
对应每组数据,输出从入口到出口最短需要几步。
示例1
输入
#.########
#…#
#…#
#…#
#…#
#…#
#…#
#…#
#…#
########.#
#.########
#…#
########.#
#…#
#.########
#…#
########.#
#…#
#.######.#
########.#
输出
16
30
// write your code here cpp
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
struct node
{
int x;
int y;
int count;
};
node dir[4] = {{0,1},{1,0},{-1,0},{0,-1}};
int bfs(vector<string> map, node begin, node end)
{
queue<node> q;
q.push(begin);
map[begin.x][begin.y] = '#';
while(!q.empty())
{
node begin = q.front();
node next;
q.pop();
for(int i = 0; i < 4; ++i)
{
next.x = begin.x + dir[i].x;
next.y = begin.y + dir[i].y;
next.count = begin.count + 1;
if(next.x == end.x && next.y == end.y)
return next.count;
if(next.x <= 9 && next.x >= 0 && next.y <= 9 && next.y >= 0 && map[next.x][next.y] == '.')
{
map[next.x][next.y] = '#';
q.push(next);
}
}
}
return 0;
}
int main()
{
vector<string> map(10);
node beginp{ 0, 1 ,0};
node endp{ 9, 8 ,0};
while(cin >> map[0][0])
{
for(int i = 0; i < 10; ++i)
{
for(int j = 0; j < 10; ++j)
{
if(i == 0 && j == 0)
continue;
else
cin >> map[i][j];
}
}
cout << bfs(map,beginp,endp) << endl;
}
return 0;
}