深信服8.25笔试第二题

小菜路过
结果显示通过
只是提供一下思路,不足之处请多指教!
#include <iostream>
using namespace std;
int main() {
    string word;
    while(cin>>word)
    {
        int cnt = 0;
        cin>>cnt;
        int hash[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        while(cnt--)
        {
            int a = 0;
            int b = 0;
            cin>>a>>b;
            for(int i = 0; i < 10; i++)
            {
                if(hash[i] == a)
                {
                    hash[i] = b;
                }
            }
        }
        for(int i = 0; i < word.size(); i++)
        {
            int num = word[i] - '0';
            word[i] = hash[num]+'0';
        }
        cout<<word<<endl;
    }
    return 0;
}


#笔试题目#
全部评论
这样的话遇到2→3、4→2、7→4这样的测试用例怎么办,建立并查集应该是hash[i] = hash[b];吧。
1 回复
分享
发布于 2020-09-15 04:35
思路是什么
点赞 回复
分享
发布于 2020-08-26 02:15
淘天集团
校招火热招聘中
官网直投
我们的思路差不多,可是显示通过率为0,气的要摔鼠标😂
点赞 回复
分享
发布于 2020-08-26 08:30

相关推荐

1 1 评论
分享
牛客网
牛客企业服务