Codeforces1157B(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?
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).
Print the maximum number you can get after applying the operation described in the statement no more than once.
#include<bits/stdc++.h>
#include<cstring>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const int N=+;
int main() {
char c[N];
ll c1[N],n;
string b;
int a[],cnt=;
cin>>n>>c;
bool flag=true;
for(int i=; i<=; i++) {
cin>>a[i];
}
for(int i=; i<n; i++) {
c1[i]=c[i]-'';
}
for(int i=; i<n; i++) {
if((c1[i])<a[c1[i]]) {
c1[i]=(a[c1[i]]);
cnt++;
} else if((c1[i])>a[c1[i]]&&cnt!=) {
break;
}
}
for(int i=; i<n; i++) {
cout<<c1[i];
}
}
思路分析:将输入的字符数组转换成整数,根据数据整数值为所给9个数序列的下标进行替换,要是所换序列大于原字符就进行替换,同时确保替换字符是连续的。
Codeforces1157B(B题)Long Number的更多相关文章
- 乘风破浪:LeetCode真题_009_Palindrome Number
乘风破浪:LeetCode真题_009_Palindrome Number 一.前言 如何判断一个整型数字是回文呢,我们可能会转换成String来做,但是还有更简单的方法. 二.Palindrome ...
- LeetCode算法题-Perfect Number(Java实现)
这是悦乐书的第249次更新,第262篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第116题(顺位题号是507).我们定义Perfect Number是一个正整数,它等于 ...
- 湖南省第六届省赛题 Biggest Number (dfs+bfs,好题)
Biggest Number 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 You have a maze with obstacles and non-zero di ...
- leetcode 第九题 Palindrome Number(java)
Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...
- leetcode第九题--Palindrome Number
Problem: Determine whether an integer is a palindrome. Do this without extra space. click to show sp ...
- LeetCode算法题-Prime Number of Set Bits in Binary Representation(Java实现)
这是悦乐书的第311次更新,第332篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第180题(顺位题号是762).给定两个正整数L和R,在[L,R]范围内,计算每个整数的 ...
- LeetCode算法题-Largest Number At Least Twice of Others(Java实现)
这是悦乐书的第308次更新,第328篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第177题(顺位题号是747).在给定的整数数组中,总有一个最大的元素.查找数组中的最大 ...
- LeetCode算法题-Binary Number with Alternating Bits(Java实现)
这是悦乐书的第292次更新,第310篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第160题(顺位题号是693).给定正整数,检查它是否具有交替位:即它的二进制数的任意两 ...
- LeetCode算法题-Fibonacci Number(Java实现)
这是悦乐书的第250次更新,第263篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第117题(顺位题号是509).Fibonacci数字,通常表示为F(n),形成一个称为 ...
随机推荐
- javascript-文件File转换成base64格式
不能直接访问用户计算机中的文件,一直都是Web应用开发中的一大障碍.2000年以前,处理文件的唯一方式就是在表单中加入<input type="file">字段,仅此而 ...
- 2019-2020-1 20199326《Linux内核原理与分析》第三周作业
第三周学习内容 庖丁解牛Linux内核分析第二章:操作系统是如何工作的 Linux内核分析实验二 学到的一些知识 计算机的三大法宝:存储程序计算机,函数调用堆栈,中断 堆栈是C语言程序运行时必须使用的 ...
- [QT] QProcess finished 信号,关联的 slot 必须检查返回码
void QProcess::finished(int exitCode, QProcess::ExitStatus exitStatus)
- linux sort 命令实用手册
Linux 中的sort 命令是一个很实用的工具,用于对文本内容以行为单位进行ASCII 码排序,默认按照升序进行排序(当然也可以按照降序). sort 命令的格式如下: sort `参数` `文件名 ...
- SpringBoot Mybatis-Plus 整合 dynamic-datasource-spring-boot-starter 对数据库进行读写分离
准备工作 对 MySql 进行主从搭建 引入 dynamic-datasource-spring-boot-starter 坐标 引入 druid-spring-boot-starter 坐标 对应框 ...
- 解决Idea配置文件不显示中文的问题
1.首先我们的IDEA文件编码一般都修改为utf-8(setting-->file encodings--->Global Encoding 和 Project Encoding 都设置为 ...
- element UI排坑记(一):判断tabs组件是否切换
之所以将这个问题列在排坑记之中,是因为官方组件的一个属性颇有些隐蔽,这个问题曾经折腾了本人较多时间,始终思维固着,且使用搜索引擎也不容易搜索到答案,故记之.然而实际解决却是相当简单的. 一.问题描述 ...
- 如何将MAC的 Terminal 行首变得清爽简洁一点?
作为一位开发人员,MAC带给我们更好的编程体验,Terminal也是经常会去操作的东西,但是说实话,默认的 Terminal 的各种设置,真的让我好难受 刚开始打开,可能看到的会是这样的,行首一大堆东 ...
- C++类学习(2)
Ⅰ:类概念 一:类的构成 class 类名 { public: 公有数据成员和成员函数:类的接口 protected: 保护数据成员和成员函数: private: 私有数据成员和成员函数: }://注 ...
- CentOS安装jsoncpp
两种安装方式: 通过cmake安装 通过scons安装 cmake安装见cmake安装jsoncpp,scons安装见下文. 1. 安装scons .tar.gz export MYSCONS=/ro ...