B. Long Number

You are given a long decimal number aa consisting of nn digits from 11 to 99. You also have a function ff that maps every digit from 11 to 99 to some (possibly the same) digit from 11 to 99.

You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in aa, and replace each digit xx from this segment with f(x)f(x). For example, if a=1337a=1337, f(1)=1f(1)=1, f(3)=5f(3)=5, f(7)=3f(7)=3, and you choose the segment consisting of three rightmost digits, you get 15531553 as the result.

What is the maximum possible number you can obtain applying this operation no more than once?

Input

The first line contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of digits in aa.

The second line contains a string of nn characters, denoting the number aa. Each character is a decimal digit from 11 to 99.

The third line contains exactly 99 integers f(1)f(1), f(2)f(2), ..., f(9)f(9) (1≤f(i)≤91≤f(i)≤9).

Output

Print the maximum number you can get after applying the operation described in the statement no more than once.

  1. #include<bits/stdc++.h>
  2. #include<cstring>
  3. #include <stdlib.h>
  4. using namespace std;
  5. typedef long long ll;
  6. const int N=+;
  7. int main() {
  8. char c[N];
  9. ll c1[N],n;
  10. string b;
  11. int a[],cnt=;
  12. cin>>n>>c;
  13. bool flag=true;
  14. for(int i=; i<=; i++) {
  15. cin>>a[i];
  16. }
  17. for(int i=; i<n; i++) {
  18. c1[i]=c[i]-'';
  19. }
  20. for(int i=; i<n; i++) {
  21. if((c1[i])<a[c1[i]]) {
  22. c1[i]=(a[c1[i]]);
  23. cnt++;
  24. } else if((c1[i])>a[c1[i]]&&cnt!=) {
  25. break;
  26. }
  27. }
  28. for(int i=; i<n; i++) {
  29. cout<<c1[i];
  30. }
  31. }

思路分析:将输入的字符数组转换成整数,根据数据整数值为所给9个数序列的下标进行替换,要是所换序列大于原字符就进行替换,同时确保替换字符是连续的。

Codeforces1157B(B题)Long Number的更多相关文章

  1. 乘风破浪:LeetCode真题_009_Palindrome Number

    乘风破浪:LeetCode真题_009_Palindrome Number 一.前言 如何判断一个整型数字是回文呢,我们可能会转换成String来做,但是还有更简单的方法. 二.Palindrome ...

  2. LeetCode算法题-Perfect Number(Java实现)

    这是悦乐书的第249次更新,第262篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第116题(顺位题号是507).我们定义Perfect Number是一个正整数,它等于 ...

  3. 湖南省第六届省赛题 Biggest Number (dfs+bfs,好题)

    Biggest Number 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 You have a maze with obstacles and non-zero di ...

  4. leetcode 第九题 Palindrome Number(java)

    Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...

  5. leetcode第九题--Palindrome Number

    Problem: Determine whether an integer is a palindrome. Do this without extra space. click to show sp ...

  6. LeetCode算法题-Prime Number of Set Bits in Binary Representation(Java实现)

    这是悦乐书的第311次更新,第332篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第180题(顺位题号是762).给定两个正整数L和R,在[L,R]范围内,计算每个整数的 ...

  7. LeetCode算法题-Largest Number At Least Twice of Others(Java实现)

    这是悦乐书的第308次更新,第328篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第177题(顺位题号是747).在给定的整数数组中,总有一个最大的元素.查找数组中的最大 ...

  8. LeetCode算法题-Binary Number with Alternating Bits(Java实现)

    这是悦乐书的第292次更新,第310篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第160题(顺位题号是693).给定正整数,检查它是否具有交替位:即它的二进制数的任意两 ...

  9. LeetCode算法题-Fibonacci Number(Java实现)

    这是悦乐书的第250次更新,第263篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第117题(顺位题号是509).Fibonacci数字,通常表示为F(n),形成一个称为 ...

随机推荐

  1. 微信jssdk遇到的一些问题汇总

    1.用户手动去触发的接口可以直接调用比如wx.startRecord(); 但是写在页面加载完成里就无效,需要写在 wx.ready(function(){ wx.startRecord(); }); ...

  2. 2019-2020-1 20199303《Linux内核原理与分析》第六周作业

    系统调用的三层机制 首先是为系统增加新的命令 运行脚本自动生成文件系统 其中有一个显示时间的功能 编辑test.c文件,增加一个hello函数用来显示学号,再次使用make roofts自动编译,调用 ...

  3. 数据包的抓取[tcpdump]的应用

    [root@server ~]# yum install tcpdump [root@server ~]# yum install wireshark 1.默认情况下,直接启动tcpdump将监视第一 ...

  4. QT bug ig9icd64.dll

    QT bug ig9icd64.dll bugintel ig9icd64.dll 处有未经处理的异常 遇到了一个 奇奇怪怪的bug, 一般的QT程序中 在main.cpp 中初始化一个窗口进行显示后 ...

  5. 【linux题目】第三关

    1. 解释下什么是GPL,GNU,自由软件? 2. 如何选择Linux操作系统版本? 3. 安装系统时如何给Linux操作系统分区? 4. 描述Linux系统的启动过程? 5. 简要说出20个Linu ...

  6. 从Webpack源码探究打包流程,萌新也能看懂~

    简介 上一篇讲述了如何理解tapable这个钩子机制,因为这个是webpack程序的灵魂.虽然钩子机制很灵活,而然却变成了我们读懂webpack道路上的阻碍.每当webpack运行起来的时候,我的心态 ...

  7. Computational Geometry

    矩形重叠 看过某司一道笔试题:给\(n\)个矩形左下和右上坐标(不能斜放),求重叠最多处矩形个数. 这道题本身不难:可以遍历所有矩形边界组成的点,计算该点被多少矩形包围,从而选出最大值. 由此引申出一 ...

  8. Fiddler 介绍

    1.fiddler原理介绍 fiddler 是一个抓包工具,当浏览器访问服务器会形成一个请求,此时,fiddler就处于请求之间,当浏览器发送请求,会先经过 fiddler,然后在到服务器:当服务器有 ...

  9. Nginx模块开发(1)————类helloworld

    Nginx看了一点了,准备写个helloworld试试,觉得只看书的话很多东西都乱乱的,晕晕的,印象不深. 我的helloworld模块的目的就是:能够在浏览器里输入http://你的ip地址/lcw ...

  10. 第3章:关系数据库标准语言 SQL

    目录 第3章:关系数据库标准语言 SQL 3.1.SQL概述 3.1.1.历史 3.3.2.SQL语言的功能 3.3.3.SQL的特点 3.3.4.基本概念 3.2.学生-课程数据库 3.3.数据定义 ...