• Median String CodeForces


    You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is lexicographically less than tt.

    Let's consider list of all strings consisting of exactly kk lowercase Latin letters, lexicographically not less than ss and not greater than tt (including ss and tt) in lexicographical order. For example, for k=2k=2, s=s="az" and t=t="bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"].

    Your task is to print the median (the middle element) of this list. For the example above this will be "bc".

    It is guaranteed that there is an odd number of strings lexicographically not less than ss and not greater than tt.

    Input

    The first line of the input contains one integer kk (1k21051≤k≤2⋅105) — the length of strings.

    The second line of the input contains one string ss consisting of exactly kk lowercase Latin letters.

    The third line of the input contains one string tt consisting of exactly kk lowercase Latin letters.

    It is guaranteed that ss is lexicographically less than tt.

    It is guaranteed that there is an odd number of strings lexicographically not less than ss and not greater than tt.

    Output

    Print one string consisting exactly of kk lowercase Latin letters — the median (the middle element) of list of strings of length kk lexicographically not less than ss and not greater than tt.

    Examples

    Input
    2
    az
    bf
    
    Output
    bc
    
    Input
    5
    afogk
    asdji
    
    Output
    alvuw
    
    Input
    6
    nijfvj
    tvqhwp
    
    Output
    qoztvz

    题意:给你两个只含有小写字母的字符串, s和t,保证s的字典序比t小。把s和t看成一个26进制的数,让你输出这两个数的中位数。

    思路:首先把两个字符串的每一个位上的数值加起来,然后向前进位。
    然后从头开始遍历加起来的那个数值,如果数值为偶数,那么中位数的这一位就是数值/2,如果是奇数,那么中位数的这一位是/2且向下取整。
    并把那个多余的一加到下一位中,(注意上一位的1到下一位是26),最后输出答案即可。 *(主要是通过咱们熟悉的十进制来找到转换的规律,然后处理。)
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <vector>
    #include <iomanip>
    #define ALL(x) (x).begin(), (x).end()
    #define rt return
    #define dll(x) scanf("%I64d",&x)
    #define xll(x) printf("%I64d
    ",x)
    #define sz(a) int(a.size())
    #define all(a) a.begin(), a.end()
    #define rep(i,x,n) for(int i=x;i<n;i++)
    #define repd(i,x,n) for(int i=x;i<=n;i++)
    #define pii pair<int,int>
    #define pll pair<long long ,long long>
    #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MSC0(X) memset((X), '', sizeof((X)))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define eps 1e-6
    #define gg(x) getInt(&x)
    #define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
    using namespace std;
    typedef long long ll;
    ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
    ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
    inline void getInt(int* p);
    const int maxn=1000010;
    const int inf=0x3f3f3f3f;
    /*** TEMPLATE CODE * * STARTS HERE ***/
    int a[maxn];
    int b[maxn];
    int main()
    {
        // freopen("D:\common_text\code_stream\in.txt","r",stdin);
        // freopen("D:\common_text\code_stream\out.txt","w",stdout);
        gbtb;
        // repd(i,0,25)
        // {
        //     cout<<(char)('a'+i)<<" ";
        // }
        string xia;
        string shang;
        int k;
        cin>>k>>xia>>shang;
        for(int i=k-1;i>=0;i--)
        {
            // a[i-1]+=(shang[i]+xia[i]-'a'-'a')/26;
            a[i]+=(shang[i]+xia[i]-'a'-'a');
        }
        for(int i=k-1;i>0;i--)
        {
            a[i-1]+=a[i]/26;
            a[i]%=26;
        }
        // repd(i,0,k)
        // {
        //     db(a[i]);
        // }
        for (int i = 0; i < k; ++i)
        {
            if(a[i]&1)
            {
                a[i+1]+=26;;
                b[i]=a[i]/2;
            }else
            {
                b[i]=a[i]/2;
            }
        }
        for (int i = 0; i < k; ++i)
        {
            cout<<(char)(b[i]+'a');
            /* code */
        }
        cout<<endl;
        return 0;
    }
    
    inline void getInt(int* p) {
        char ch;
        do {
            ch = getchar();
        } while (ch == ' ' || ch == '
    ');
        if (ch == '-') {
            *p = -(getchar() - '0');
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 - ch + '0';
            }
        }
        else {
            *p = ch - '0';
            while ((ch = getchar()) >= '0' && ch <= '9') {
                *p = *p * 10 + ch - '0';
            }
        }
    }

    本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
  • 相关阅读:
    去掉谷歌浏览器下input框自动填充的背景色
    ajax请求中动态显示问题
    Array对象的方法有
    请求页面的方法
    IE浏览器checkbox的样式问题
    property、classmethod和staticmethod总结
    面向对象和类
    内置函数补充map、reduce和filter等
    python实现控制台的进度条功能
    python常见内置函数
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/10638404.html
Copyright © 2020-2023  润新知