1144:0 start-up algorithm 51--array delete time limit:1 Sec Memory limit:64 MB 64bit IO Format:%lld
submitted:3304 accepted:933
[Submit] [Status] [Web Board] Description
Deletes a number in the given array
Input
Multiple sets of tests, enter 1 integers n (n<20) and then n integers in the first row of each group
Enter 1 integer m in the second line
Output
Delete the first number m in the first row of n integers and delete and then output the remaining number in sequence,
Sample Input
4 1 2) 3 43
Sample Output
1 2 4
HINT
M may not be found in the original array, output original array is not found
Source
0 Starting point Learning algorithm
1#include <stdio.h>2 intMain () {3 intn,a[ -];4 while(SCANF ("%d", &n)! =EOF) {5 for(intI=0; i<n;i++){6scanf"%d",&a[i]);7 }8 9 intm,t,sign=1;Tenscanf"%d",&m); One for(intI=0; i<n;i++){ A if(m==A[i]) { -t=i; -sign=0; the Break; - } - } - + if(sign) { - for(intI=0; i<n-1; i++){ +printf"%d", A[i]); A } atprintf"%d\n", a[n-1]); - } - Else{ - for(intI=0; i<t;i++){ -printf"%d", A[i]); - } in for(intj=t+1; j<n-1; j + +){ -printf"%d", A[j]); to } +printf"%d\n", a[n-1]); - } the } * return 0; $}
Feel a problem if the number of deletions is the last one??
1144:0 start-up algorithm 51--the number of deletions in an array