当前位置:网站首页>1321:【例6.3】删数问题(Noip1994)
1321:【例6.3】删数问题(Noip1994)
2022-07-07 08:14:00 【暴揍键盘的程序猿】
1321:【例6.3】删数问题(Noip1994)
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 25868 通过数: 9164
【题目描述】
输入一个高精度的正整数n,去掉其中任意s个数字后剩下的数字按原左右次序组成一个新的正整数。编程对给定的n和s,寻找一种方案使得剩下的数字组成的新数最小。
输出新的正整数。(n不超过240位)
输入数据均不需判错。
【输入】
n
s
【输出】
最后剩下的最小数。
【输入样例】
175438
4
【输出样例】
13
【算法分析】
贪心。循环s次,删掉s个大数,剩下的就是最小值。
【AC代码】
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
const int N=340;
char n[N];
int s,len,m,x;
signed main()
{
scanf("%s%d",&n,&s);
x=len=strlen(n);
for(int i=1;i<=s;i++)
{
for(int j=0;j<len-1;j++)
if(n[j]>n[j+1])//如果当前数大于下一个数
{
for(int k=j;k<len-1;k++)n[k]=n[k+1];//删掉那个数
break;//跳出循环
}
len--;//长度-1
}
while(n[m]=='0' and x>1)m++,x--;//去除前导0
for(int i=m;i<len;i++)printf("%c",n[i]);
return 0;
}

时间限制: 1000 ms 内存限制: 65536 KB
提交数: 25868 通过数: 9164
【题目描述】
输入一个高精度的正整数n,去掉其中任意s个数字后剩下的数字按原左右次序组成一个新的正整数。编程对给定的n和s,寻找一种方案使得剩下的数字组成的新数最小。
输出新的正整数。(n不超过240位)
输入数据均不需判错。
【输入】
n
s
【输出】
最后剩下的最小数。
【输入样例】
175438
4
【输出样例】
13
【算法分析】
贪心。循环s次,删掉s个大数,剩下的就是最小值。
【AC代码】
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
const int N=340;
char n[N];
int s,len,m,x;
signed main()
{
scanf("%s%d",&n,&s);
x=len=strlen(n);
for(int i=1;i<=s;i++)
{
for(int j=0;j<len-1;j++)
if(n[j]>n[j+1])//如果当前数大于下一个数
{
for(int k=j;k<len-1;k++)n[k]=n[k+1];//删掉那个数
break;//跳出循环
}
len--;//长度-1
}
while(n[m]=='0' and x>1)m++,x--;//去除前导0
for(int i=m;i<len;i++)printf("%c",n[i]);
return 0;
}

边栏推荐
猜你喜欢
【二开】【JeecgBoot】修改分页参数
Appx代碼簽名指南
The method of word automatically generating directory
Postman interface test VI
Inno setup packaging and signing Guide
ORM -- query type, association query
ES6中的原型对象
反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释
Pdf document signature Guide
Several schemes of building hardware communication technology of Internet of things
随机推荐
Prototype object in ES6
2022.7.4DAY596
Google Colab装载Google Drive(Google Colab中使用Google Drive)
LLVM之父Chris Lattner:為什麼我們要重建AI基礎設施軟件
Web3.0 series distributed storage IPFs
Sword finger offer 38 Arrangement of strings [no description written]
Easyexcel read write simple to use
BigDecimal数值比较
IPv4套接字地址结构
Postman interface test IV
Vs code specifies the extension installation location
Introduction to uboot
JMeter loop controller and CSV data file settings are used together
Differences between MCU and MPU
Download Text, pictures and ab packages used by unitywebrequest Foundation
Kotlin实现微信界面切换(Fragment练习)
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
Programming features of ISP, IAP, ICP, JTAG and SWD
@Transcation的配置,使用,原理注意事项:
The method of word automatically generating directory