zoukankan      html  css  js  c++  java
  • CF: Long Number

                                                    题目链接


    #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。” 那么为啥写成上面的形式就不难理解了,替换时只能是比它本身大或者和它本身相等,若比它小就不可以了,另外注意判断的顺序是从前往后。

  • 相关阅读:
    js 实现自增长
    常用的js脚本验证
    Jquery 收集
    Jquery 常用操作搜集
    Jquery 点击绑定行 弹出详细页面
    Jquery 了解
    Html 标尺
    Editor Guidelines
    程序员需要做到
    jS 回车事件
  • 原文地址:https://www.cnblogs.com/KeepZ/p/11143775.html
Copyright © 2011-2022 走看看