E. A Magic Lamp
E. A Magic Lamp
The question is: give you an integer, you are allowed to delete exactly m digits. The left digits will form a new integer. You should make it minimum.
You are not allowed to change the order of the digits. Now can you help Kiki to realize her dream?
Input
Each test case will contain an integer you are given (which may at most contains 1000 digits.) and the integer m (if the integer contains n digits, m will not bigger then n). The given integer will not contain leading zero.
Output
If the result contains leading zero, ignore it.
Sample Input
178543 4
1000001 1
100001 2
12345 2
54321 2
Sample Output
13
1
0
123
321
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
char str[];
int main(){
int m,len,i,top;
while(scanf("%s %d",str,&m) == ){
len = strlen(str);
top = ;
for(i = ; i < len;){
if(m && top >= && str[top] > str[i]){m--;top--;}
else if(top != - || str[i] != '') str[++top] = str[i++];
else i++;
}
while(top >= && m){top--;m--;}
if(top == -) str[++top] = '';
str[++top] = '\0';
printf("%s\n",str);
}
return ;
}
E. A Magic Lamp的更多相关文章
- HDOJ 3183 A Magic Lamp
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3183 A Magic Lamp(RMQ)
题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...
- A Magic Lamp(贪心+链表)
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3183 A Magic Lamp RMQ ST 坐标最小值
hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...
- HDU 3183 - A Magic Lamp - [RMQ][ST算法]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...
- A Magic Lamp -- hdu -- 3183
http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 3183 A Magic Lamp(RMQ)
A Magic Lamp Time Limi ...
- hdu 3183 A Magic Lamp rmq或者暴力
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- hdu A Magic Lamp
http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) ...
- HDU_3183_A Magic Lamp
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
随机推荐
- nopCommerce - asp.net开源商城
nopcommerce官网 http://nopcommerce.codeplex.com/ nopCommerce is a open source e-commerce solution that ...
- autofac 遇到构造函数问题
None of the constructors found with 'aaaaa' on type ' aaa' can be invoked with the available service ...
- hihocoder1829 Tomb Raider
思路: 暴力枚举. 实现: #include <iostream> #include <set> #include <vector> using namespace ...
- 打造自己的JavaScript武器库
自己打造一把趁手的武器,高效率完成前端业务代码. 前言 作为战斗在业务一线的前端,要想少加班,就要想办法提高工作效率.这里提一个小点,我们在业务开发过程中,经常会重复用到日期格式化.url参数转对象. ...
- Android笔记--Bitmap(三) 针对不用Android版本的位图管理
Bitmap(三) | Android不同版本的相应操作 在不同的Android版本中.位图的存储方式是不同的. 1.小于等于 Android 2.2 (API level 8) 垃圾收集器回收内存时 ...
- openstack No valid host was found. There are not enough hosts available.
root@dell-PowerEdge-T30:~# gedit /var/log/nova/nova-conductor.logroot@dell-PowerEdge-T30:~# gedit /v ...
- 最近在准备面试,总结了几个java中面向对象的几个问题,问题本事还不够全面,要想知道还是要自己去找,但是在面试上应该是没多大问题了
Overload(重载)与Override(重写)的区别 重载:发生在一个类中,方法名称相同,参数列表不同,方法体不同(看对象类型) 重写:发生在父类中,方法名称相同,参数列表相同,方法体不同(看引用 ...
- Django 表增加外键
1.创建临时表,并把原表的数据复制到临时表 先根据python manage syl article查看创建临时表 CREATE TABLE `article_article_temp` ( `id` ...
- Lesson2
#ifdef __cplusplus #include <cstdlib> #else #include <stdlib.h> #endif #include <SDL/ ...
- Feign-请求不同注册中心的服务
场景 需要通过Feign Client请求,其他注册中心或者其他Restful服务. 临时方案 Feign 请求转为RestTemplate http请求. 优点:能适应,feign环境和非feign ...