SWUST OJ Delete Numbers(0700)

Delete Numbers(0700)

Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 1731 Accepted: 373

Description

给定n 位正整数a,去掉其中任意k≤n 个数字后,剩下的数字按原次序排列组成一个新的正整数。对于给定的n位正整数a(n<100) 和正整数k,设计一个算法找出剩下数字组成的新数最小的删数方案。 对于给定的正整数a,编程计算删去k个数字后得到的最小数。

Input

第1 行是1 个正整数a。第2 行是正整数k。

Output

计算出的最小数(输出无前导0)

Sample Input

178543

4

Sample Output

13

Hint

Source

mryang

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     char str[100];
 6     int LEN,i,j,t,flag=0,k;
 7     scanf("%s",str);
 8     scanf("%d",&k);
 9     LEN=strlen(str);
10     for(i=0;i<k;i++)
11     {
12         for(j=0;j<LEN-1;j++)
13         {
14             if(str[j]>str[j+1])
15             {
16                 for(t=j;t<LEN-1;t++)
17                 {
18                     str[t]=str[t+1];
19                 }
20             break;
21             }
22         }
23         LEN--;
24     }
25     for(i=0;i<LEN;i++)
26     {
27         if(flag==0&&str[i]==‘0‘)
28         {}
29         else
30         {
31             printf("%c",str[i]);
32             flag=1;
33         }
34     }
35     printf("\n");
36     return 0;
37 }

注:从高位开始,遇到降序则删除那个大的数,最后没有降序了,再考虑最后面的数,注意前导没有0。

时间: 2024-10-17 13:34:03

SWUST OJ Delete Numbers(0700)的相关文章

Delete Numbers(swust oj 0700)

Description:http://acm.swust.edu.cn/problem/0700/ AC代码: #include<stdio.h> #include<string.h> int main() { char digit[2000]; while(scanf("%s",digit)!=EOF){ int len=strlen(digit); int del,i,j; scanf("%d",&del); int head=0

SWUST OJ Euclid&#39;s Game(0099)

Euclid's Game(0099) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 1855 Accepted: 589 Description Starts with two unequal positive numbers (M,N and M>N) on the board. Two players move in turn. On each move, a player has to write on the boar

swust oj 1026--Egg pain&#39;s hzf

题目链接:http://acm.swust.edu.cn/problem/1026/ Time limit(ms): 3000 Memory limit(kb): 65535 hzf is crazy about reading math recently,and he is thinking about a boring problem. Now there are n integers Arranged in a line.For each integer,he wants to know

swust oj 649--NBA Finals(dp,后台略(hen)坑)

题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two teams, Lakers and Celtics, playing a series of NBA Finals until one of the teams wins n games. Assume that the probability of Lakers winning a game is

线段树 [SWUST OJ 764] 校门外的树 Plus Plus

校门外的树 Plus Plus(0764) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 214 Accepted: 15 Description 西南某科技大学的校门外长度为 L 的公路上有一排树,每两棵相邻的树之间的间隔都是 1 米.我们可以把马路看成一个数轴,马路的一端在数轴 1 的位置,另一端在 L 的位置:数轴上的每个整数点,即 1,2,……,L,都种有一棵树. 现在要将这排树的某一段涂成某种颜色,给定 N 组区间[ 

背包 [POJ 2184 SWUST OJ 145] Cow Exhibition

Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9479   Accepted: 3653 Description "Fat and docile, big and dumb, they look so stupid, they aren't much  fun..."  - Cows with Guns by Dana Lyons The cows want to prove to

[Swust OJ 404]--最小代价树(动态规划)

题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Description 以下方法称为最小代价的字母树:给定一正整数序列,例如:4,1,2,3,在不改变数的位置的条件下把它们相加,并且用括号来标记每一次加法所得到的和. 例如:((4+1)+ (2+3))=((5)+(5))=10.除去原数不4,1,2,3之外,其余都为中间结果,如5,5,10,将中间结果相加

[Swust OJ 234]--IrreducibleNumber(题意太坑)

题目链接:http://acm.swust.edu.cn/problem/0234/ Time limit(ms): 1000 Memory limit(kb): 65535 Description You are given a list of number. An integer K is irreducible with respect to the numbers if K cannot be represented as a sum of one or more elements fr

swust oj 1126--神奇的矩阵(BFS,预处理,打表)

题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈特13成功解决了填数矩阵问题.不知道他这一周又从哪儿弄来一神奇的矩阵,于是逃课潜心研究了一周,终于发现了其中的奥秘:该矩阵有2行.4列,即8个小方块,每个小方块上有一个数字,即:1 2 3 45 6 7 8对于这个神奇的矩阵,有3种变换方式,具体如下:变换A:上下两行数字互换,如上图可变为:5 6