前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CF: Long Number

CF: Long Number

作者头像
_DIY
发布2019-09-11 17:24:17
5530
发布2019-09-11 17:24:17
举报

题目链接


代码语言:javascript
复制
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string a;
    cin >> a;
    int f[10];
    for(int i = 1; i <= 9; i++)
        cin >> f[i];
    for(int i = 0; i < n; i++)
    {
        if(f[a[i] - '0'] > (a[i] - '0'))
        {
            int j = i;
            while(j < n && f[a[j] - '0'] >= (a[j] - '0'))  /*这里要注意j的边界问题,至于为什么 >= 见分析1*/
            {
                a[j] = f[a[j] - '0'] + '0';
                j++;
            }
            break;

        }
    }
    cout << a << endl;
}

分析1:题目原文中有这么一句“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).”, 谷歌翻译后结果为 “您可以执行以下操作不超过一次:在a中选择一个非空的连续子数字段,并用f(x)替换该段中的每个数字x。” 那么为啥写成上面的形式就不难理解了,替换时只能是比它本身大或者和它本身相等,若比它小就不可以了,另外注意判断的顺序是从前往后。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-05-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目链接
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档