Alphabetic Removals(思维+模拟)

Keil5编译报错:ARM Compiler Version 5缺失的完整解决方案 本文提供了Keil5编译报错“ARM Compiler Version 5缺失”的完整解决方案。详细介绍了手动安装ARM Compiler Version 5的步骤,包括下载安装包、配置编译器路径及常见问题排查,帮助开发者快速恢复老项目的编译环境。 阅读详情

Alphabetic Removals

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
题意:

给了n和k,然后输入一个长度为n的字符串,然后有k次操作,从字符串中依次按abcd…的顺序删除字符,最后输出k次操作后的字符串。

外面的循环用来标记26个英文字母,里面的循环用来遍历字符串,然后就是按照题意那样删除字符了,删除记为0,输出的时候不输出0即可。

code:

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main(){
    int n,k;
    string str;
    cin >> n >> k;
    cin >> str;
    for(int i = 0; i < 26; i++){
        for(int j = 0; j < n && k; j++){
            if(str[j] == 'a' + i){
                str[j] = '0';
                k--;
            }   
        }
    }
    for(int i = 0; i < n; i++){
        if(str[i] != '0') cout << str[i];
    }
    cout << endl;
    return 0;
}
状态机设计与实现( stm32小车避障为例) 本文以STM32小车避障为例,介绍了状态机设计与实现方法。首先阐述了状态机的事件驱动特性、清晰结构和易扩展优势,并给出硬件组成框架。核心实现部分展示了状态枚举定义、状态转移图和主循环框架,通过switch-case结构实现状态切换。关键状态示例包括前方扫描和转向决策逻辑,通过传感器数据驱动状态转移。总结指出状态机设计需定义枚举状态、实现状态函数、使用switch跳转并更新全局状态。文章最后声明内容为学习笔记,欢迎读者指正交流。全文结构清晰,代码示例具体,为嵌入式系统状态机设计提供了实用参考。 阅读详情

相关推荐

c语言【分糖果】2023蓝桥杯4124(枚举,递归,dfs)

但是这是不符合我们糖果刚好分完的条件的,我们应该往回退到上一层,也就是孩子6这层,然后j+1=3,孩子7分到3个第二种糖果,这也不符合我们糖果刚好分完的条件,然后就会再次回退到孩子6这里,然后j+1=4,让我们的孩子7获得5块第二种糖果,然后还是不符合糖果刚分完的条件,于是再一次退回到孩子6这里,然后就会有外循环i+1=1,j=1,孩子7分到1块第一种糖果1块第二块糖果......然后就是这样的不停地回溯,试探,直到把整棵树遍历一遍,并且记录所有的满足条件的组合。先放一下我的代码,我的代码超时啦救命!

weixin_74331419的博客 738

【题解】Building Strings Gym - 102152E

【题面】 You are given a string s of length n consisting of lowercase English letters. This string can be used to build other strings. The cost of each letter in s is given by another string c of length n consisting of digits, such that the cost of using ...

深蓝旭的博客 796

ST-CNN实战:用Python实现交通流量预测(附完整代码)

本文详细介绍了如何利用时空卷积神经网络(ST-CNN)进行交通流量预测的实战过程。通过Python和PyTorch,从数据预处理、构建邻接矩阵,到ST-CNN核心模块的代码实现与模型训练,提供了完整的解决方案,帮助开发者掌握处理时空序列数据的核心算法。

rust6ferris的博客 939

CodeForces - 999C Alphabetic Removals -

output standard output You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly kk characters (k≤nk≤n) from the string ss. Polycarp uses the following alg...

Sean 440

从零构建AI辅助逆向分析环境:JADX-MCP与LLM的实战集成指南

本文详细介绍了如何从零构建AI辅助逆向分析环境,通过集成JADX-MCP与LLM技术,提升Android应用逆向工程效率。文章涵盖环境搭建、插件安装、MCP服务器配置及实战案例分析,帮助开发者快速掌握AI在代码理解、漏洞挖掘和自动化文档生成中的应用。

weixin_27875131的博客 847

北京理工大学计算机学院赵曜,中国进出口银行2016年度拟接收毕业生情况公示...

《中国进出口银行2016年度拟接收毕业生情况公示》由会员分享,可在线阅读,更多相关《中国进出口银行2016年度拟接收毕业生情况公示(5页珍藏版)》请在技术文库上搜索。1、二级(三级)单位二级(三级)单位姓名姓名性别性别学历学历毕业学校毕业学校专业专业 中国进出口银行总行 机关 许凯男硕士研究生北京大学法学 中国进出口银行总行 机关 冯晨男硕士研究生北京大学教育技术学 中国进出口银行总行 机关 刘鹏...

weixin_42168902的博客 4281

C - Alphabetic Removals

题目链接: You are given a stringssconsisting ofnnlowercase Latin letters. Polycarp wants to remove exactlykkcharacters (k≤nk≤n) from the stringss. Polycarp uses the following...

diaomeijiao3430的博客 245

别再死记硬背参数了!手把手教你用Fluent欧拉模型搞定流化床模拟(附颗粒粘度/体积分数设置详解)

本文深入解析Fluent欧拉模型在流化床模拟中的应用,重点讲解颗粒粘度和体积分数等关键参数的设置原理与科学方法。通过对比不同模型(如Syamlal-O'Brien、Gidaspow)的适用场景,帮助工程师摆脱参数死记硬背,实现精准模拟。内容涵盖相间作用机制、求解策略优化及结果验证,为化工、能源领域的流化床模拟提供实用指南。

weixin_42656416的博客 438

Codeforces 888C:K-Dominant Character

题目链接K-Dominant CharacterTime limit:2 seconds Memory limit:256 megabytes Problem DescriptionYou are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each sub

并非所有流浪者都迷失了自我 1616

UR机械臂正逆运动学解析:从DH参数到8组解的完整求解策略

本文深入解析UR机械臂的正逆运动学求解策略,从DH参数原理到完整的8组解求解方法。详细介绍了正运动学的坐标变换过程,以及逆运动学中Atan2函数和三角恒等变换的应用,并揭示了8组解的产生机制。通过实际案例和调试技巧,帮助工程师掌握UR机械臂运动学求解的核心技术。

weixin_29094775的博客 422

ABAP 7.40 新语法介绍系列之六:使用 FILTER 关键字对 ABAP 内表进行过滤

笔者之前写过的关于 ABAP 740 新语法的文章:本文介绍另一个新的关键字:FILTER.FILTER 是 ABAP 740 中引入的一个关键字,用于简化数据操作,它能够将内部表(Internal Table)中的数据按特定的条件进行过滤,并生成一个新的内部表。FILTER 的引入旨在使代码更加现代化和高效,尤其是在面对大量数据需要过滤的情况下。传统上,开发人员可能需要使用 LOOP AT 结合条件判断来实现,但使用 FILTER 关键字后,代码显得更加简洁且易于维护。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1194

You're given a string of lower-case Latin letters. Your task is to find the length of its longest su

C - You're Given a String...  代码:import java.util.Arrays;import java.util.Scanner;public class Main {public static void main(String[] args){  int count=1,k=0,max=0,i=0;  int[] sum=new int[100];  Sca...

L427630的博客 3370

挂载(Mount)是什么意思

挂载 = 把一个存储设备或文件系统“接入”到现有的目录树,使其内容能够被访问。

天赐好车的博客 299

[Codeforces]Codeforces Round #490 (Div. 3)

Mishka and Contest #pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JUDGE #include "stdafx.h" #else #include<bits/stdc++.h> #endif using namespace std; typedef lo...

weixin_30375427的博客 156

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

CodeForces A. Letters Cyclic Shift【字符串】

A. Letters Cyclic Shift time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a non-empty string s c

所谓梦想,就是永不停息的疯狂。。。。。 1810

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Alphabetic Removals

问题描述:You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly kk characters (k≤nk≤n) from the string ss. Polycarp uses the following algorithm kk times:if t...

someng的博客 340

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

C. Alphabetic Removals

http://codeforces.com/contest/999/problem/C 给n个字母,删掉k个, 从a开始删,删完了a再开始删b ,一直到z, 输出剩下的字符 import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { ...

美丽的大黄人 383

String Typing(字符串操作)

You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perfo...

好吗好的~的技术博客 2250

Alphabetic Removals(CodeForces - 999C )

You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly kk characters (k≤nk≤n) from the string ss. Polycarp uses the following algorithm kk times: if ther...

Baiyi_destroyer的博客 539

Educational Codeforces Round 53 (Rated for Div. 2) A. Diverse Substring

A. Diverse Substring   You are given a string ss, consisting of nn lowercase Latin letters. A substring of string ss is a continuous segment of letters from ss. For example, "defor" is a substring ...

s540239976的博客 758

Codeforces Round #490 (Div. 3)--Mishka and Contest,Reversing Encryption,Alphabetic Removals

A. Mishka and Contesttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka started participating in a programming contest. There are nn problems i...

maozhengxiang的博客 548

Diverse Substring(CF-1037A)

Problem Description You are given a string s, consisting of nn lowercase Latin letters. A substring of string s is a continuous segment of letters from ss. For example, "defor" is a substring of "c...

Alex_McAvoy的博客 952

codeforces-954B(模拟+贪心字符串复制)

题面: You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may ...

小冰球 987

补题向 | Segment Occurrences(字符串)

B. Segment Occurrences You are given two strings ss and tt, both consisting only of lowercase Latin letters. The substring s[l..r]s[l..r] is the string which is obtained by taking characters sl,sl+1...

bekote的博客 747

A. Mike and palindrome

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a string s consisting of only lowercase English letters

无知的我 1986

999C - Alphabetic Removals

C. Alphabetic Removalstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string ss consisting of nn lowercase Latin letters. Polycarp...

memory_qianxiao的博客 812
上一篇: Intersecting Lines POJ - 1269(计算几何判断直线位置关系+求直线交点)
下一篇: String painter HDU - 2476(区间DP)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址