每日一题

59 篇文章 0 订阅
49 篇文章 1 订阅

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值