Median String 26 hex plus and division

Topic link: http: //codeforces.com/problemset/problem/1144/E

Question is intended: to two strings, the first string is less than the second string, the first string is greater than or equal request is less than all equal to the second intermediate string string string.

Ideas: In the beginning I think this question is very difficult ah, if one by one to find, with demand for circulation, demand really does not come out, but I see other people's ideas, and found it very simple, in fact, can be seen as the string into 26 system number, and then find the median, then solved into a string.

AC Code

#include<iostream>
#include<string>
using namespace std;
const int MAX=2e5+10;
int a[MAX];
string b="abcdefghijklmnopqrstuvwxyz";
int main()
{
    int n;
    cin>>n;
    string s1,s2;
    cin>>s1>>s2;
    int jinwei=0;
    for(int i=n-1;i>=0;i--)
    {
        int sum=jinwei+s1[i]-'a'+s2[i]-'a';
        jinwei=sum/26;
        a[i]=sum;
        if(jinwei>0&&i!=0)a[i]-=26;
    }
    int shengyu=0;
    for(int i=0;i<n;i++)
    {
        int sum=a[i]+shengyu*26;
        a[i]=sum/2;
        shengyu=sum%2;
    }
    for(int i=0;i<n;i++)
    {
        cout<<b[a[i]];
    }
    return 0;
} 

 

Guess you like

Origin www.cnblogs.com/xlbfxx/p/11270023.html