Home > Back-end >  Delete a few problems
Delete a few problems

Time:11-04

Behind the start I noticed if the number is greater than the number of, then the number out, taking into consideration the repeat the whole s final time rather than delete s from left to right, and the equal number of CARDS in a row for a while. And finally 0 problems... Summary, thinking, thinking.
#include
#include//formatted input and output the header file and the string header file
Char n [250].//use of character arrays to store high precision degree
The int "s, I, len, flag=1;
Int main ()
{
While (the scanf (" % s % d ", n, & amp; S)! EOF)={

flag=1;
Len=strlen (n);
//int len1=len;//here is the length function, get the length of the n and assigned to len
While (s!=0)//as long as s is not zero, take the number of work done, no!
{
i=0;
While (n [I] <[I=n + 1))//brackets condition ensures not descending order, when it exits, is ascending sequence at the end of the
//note that the end of the string is very clever \ 0 this
i++;
while(i{n=n + 1] [I [I]; i++; }//but this cycle can use erase (I, 1); Replace
//crazy.
Len -;//remove the digital length after minus 1
S -;//consume a number out
}
for(int i=0; i{
If (n==[I] '0' & amp; & icontinue;//skip
The else
{printf (" % c ", n [I]); flag=0; }//output and clear n [I] is no longer the highest
}
printf("\n");
//for (int I=0; i//printf (" % c ", n [I]);
//}
}
return 0;
}

CodePudding user response:

Didn't see specific to realize what function?

Can use the bubble sort the ideas behind the delete data

CodePudding user response:

Problem description: given n positive integers a, remove k< them;=n number, the rest of the Numbers in the original order to form a new positive integer, for a given n is a positive integer a and positive integer k, design an algorithm to find the remaining Numbers count the smallest delete new scheme,

Programming calculation for the given positive integer a, delete k number after get the minimum number of,

The input file example:

178543

4

Output file example:

13

2. The related algorithm:

#include
6 # define M
Int main () {
Int arr []=,7,8,5,4,3 {1};
Int arrMark []=,0,0,0,0,0 {0};//is used as the marker of array, delete members down to 1 said, remember to delete
0 means notInt delNum;//want to delete the number of
int i;
int j;
Int next=0;//record a tag is not delete the subscript

The scanf (" % d ", & amp; DelNum);//the number of input to delete

for(i=0; ifor(j=0; jIf (j==M - 1) {//if it is the last element, it can be directly deleted
ArrMark [j]=1;
break;
}
While (next<=j | | arrMark [next]==1) {//find the next mark not delete the subscript
Next++;
}
If (arrMark [j].=1 & amp; & Arr [j] & gt; Arr [next]) {//if found in descending order, delete
ArrMark [j]=1;
break;
}
}
Next=0;
}

for(i=0; iIf (arrMark [I]!
=1)Printf (" % d ", arr [I]);
}
}
3. The problem analysis and problem solving thinking:

Digital is higher, the greater the impact on the size of the digital eventually will, so it's best to delete digital high number, and if it is deleted between adjacent digital larger Numbers, the end result will be small, so we can to find it from the highest place, find the first is larger than himself under a digital number to delete, so every time processing, can get final target as a result,
  • Related