7 19 个人赛 to me ( 字符串因子逆序 删k次字符串)

A string s of length n

can be encrypted by the following algorithm:

  • iterate over all divisors of n in decreasing order (i.e. from n to 1),for each divisor d, reverse the substring s[1…d] (i.e. the substring which starts at position 1 and ends at position d).
  • For example, the above algorithm applied to the string s="codeforces" leads to the following changes: "codeforces" → "secrofedoc" → "orcesfedoc" → "rocesfedoc" → "rocesfedoc" (obviously, the last reverse operation doesn't change the string because d=1).

    You are given the encrypted string t. Your task is to decrypt this string, i.e., to find a string s such that the above algorithm results in string t. It can be proven that this string s always exists and is unique.

    Input

    The first line of input consists of a single integer n(1≤n≤100) — the length of the string t. The second line of input consists of the string t. The length of t is n, and it consists only of lowercase Latin letters.

    Output

    Print a string s such that the above algorithm results in t

    Examples

    Input

    10
    rocesfedoc
    

    Output

    codeforces
    

    Input

    16
    plmaetwoxesisiht
    

    Output

    thisisexampletwo
    

    Input

    1
    z
    

    Output

    z
    

    Note

    The first example is described in the problem statement.

是真水

解题说明:此题为字符反转题,题意:给一个长度为n的字符串,经过他的因子个数的几次翻转,让你求最初的字符串。模拟 那就从2开始判断是不是n的因子,是的话,就翻转从前面到因子的字符串。

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAX 1000000
#include <deque>
using namespace std;
deque <int> dq;
int main()
{
    int d,i,a[100]={0};
    char s[120],t;
    memset(s,0,sizeof(s));
    scanf("%d",&d);
    getchar();
    gets(s);
    if(d==1)
    {
        puts(s);
        return 0;
    }
    int e=0;
    for(i=2;i<d;i++)
    {
        if(d%i==0)
        {
            a[e++]=d/i;
        }
    }
    sort(a,a+e);
    a[e]=d;
    int m=e+1;
    e=0;
    while(m--)
    {
        if(a[e]==0)
            break;
        for(i=0;i<a[e]/2;i++)
        {
            t=s[i];
            s[i]=s[a[e]-i-1];
            s[a[e]-i-1]=t;
        }
        e++;
    }
    puts(s);
    return 0;
}

You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k≤n) from the string s. Polycarp uses the following algorithm k

times:

  • if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
  • if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
  • ...
  • remove the leftmost occurrence of the letter 'z' and stop the algorithm.

This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k

times, thus removing exactly k

characters.

Help Polycarp find the resulting string.

Input

The first line of input contains two integers n

and k (1≤k≤n≤4⋅105

) — the length of the string and the number of letters Polycarp will remove.

The second line contains the string s

consisting of n

lowercase Latin letters.

Output

Print the string that will be obtained from s

after Polycarp removes exactly k letters using the above algorithm k

times.

If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).

Examples

Input

15 3
cccaabababaccbc

Output

cccbbabaccbc

Input

15 9
cccaabababaccbc

Output

cccccc

Input

1 1
u

Output

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAX 1000000
#include <deque>
using namespace std;
char s[1000000];
int main()
{
    long long int n,k,i,j;
    scanf("%lld%lld",&n,&k);
    getchar();
    gets(s);
    for(i='a';i<='z';i++)
    {
        for(j=0;j<n;j++)
        {
            if(s[j]==i)
            {
                s[j]=1;
                k--;
            }
            if(k==0)
            break;
        }
        if(k==0)
            break;
    }
    for(i=0;i<n;i++)
        if(s[i]!=1)
           printf("%c",s[i]);
    return 0;
}

 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值