题目:

题目来源WUSTOJ

源代码:

#include<stdio.h>
int main() {
int n, m, i, a[20];
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) {
scanf("%d", &a[i]); // 输入n个整数
}
scanf("%d", &m); //输入m
for (i = 0; i < n; i++) {
if (m == a[i]) { // 数组中找到了整数m
n--; // n减1
for (; i < n; i++) {
a[i] = a[i + 1]; // 将以后的数向前移一位
}
}
}
if (n != 0) { // 删除后数组中至少有1个整数
for (i = 0; i < n - 1; i++) {
printf("%d ", a[i]);
}
printf("%d\n", a[i]); // 最后一个数换行
}
}
return 0;
}

测试数据:

数据1:

4 1 2 3 4
0

结果:

1 2 3 4

数据2:

4 1 2 3 4
1

结果:

2 3 4

数据3:

4 1 2 3 4
4

结果:

1 2 3

数据4:

1 2
2

结果:


注意:

  1. 多组输入
  2. 最后换行
  3. 删除后没有数的话,不需要输出任何东西
  4. 数组中没有m的话,原样输出

截图:

1144: 零起点学算法51——数组中删数(C语言)的更多相关文章

  1. 1145: 零起点学算法52——数组中删数II

    1145: 零起点学算法52--数组中删数II Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 293 ...

  2. Problem D: 零起点学算法83——数组中删数

    #include<stdio.h> int main(void) { int n,i,t,x,flag; while(scanf("%d",&n)!=EOF) ...

  3. Problem E: 零起点学算法84——数组中删数II

    #include<stdio.h> int main() { ],b[],i,flag=; while(scanf("%d",&n)!=EOF) { ;i< ...

  4. Problem F: 零起点学算法85——数组中插入一个数

    #include<stdio.h> int main() { ],b[]; while(scanf("%d",&n)!=EOF) { ;i<n;i++) ...

  5. Problem C: 零起点学算法82——数组中查找数

    #include<stdio.h> int main(void) { ],m; while(scanf("%d",&n)!=EOF) { ;i<n;i++ ...

  6. 1129: 零起点学算法36——3n+1问题

    1129: 零起点学算法36--3n+1问题 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 4541 ...

  7. 1164: 零起点学算法71——C语言合法标识符(存在问题)

    1164: 零起点学算法71——C语言合法标识符 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 10 ...

  8. 1163: 零起点学算法70——Yes,I can!

    1163: 零起点学算法70--Yes,I can! Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: ...

  9. 1147: 零起点学算法54——Fibonacc

    1147: 零起点学算法54--Fibonacc Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 20 ...

随机推荐

  1. vue+elementui搭建后台管理界面(2首页)

    1 会话存储 使用html5的 sessionStorage 对象临时保存会话 // 保存会话 sessionStorage.setItem('user', username) // 删除会话 ses ...

  2. arcgis python 异常处理

    import arcpy in_features = "c:/base/transport.gdb/roads" try: # Note: CopyFeatures will al ...

  3. 【idea】断点调试时查看所有变量和静态变量

    转载至博客:https://blog.csdn.net/qq32933432/article/details/86672341 缘起 笔者在进行HashMap原理探索的时候需要在IntelliJ ID ...

  4. [root@offical nginx]# nginx -t nginx: [emerg] module "/usr/lib64/nginx/modules/ngx_http_geoip_module.so" version 1012002 instead of 1016001 in /usr/share/nginx/modules/mod-http-geoip.conf:1 nginx: con

    [root@offical nginx]# nginx -tnginx: [emerg] module "/usr/lib64/nginx/modules/ngx_http_geoip_mo ...

  5. OpenCv dnn模块扩展研究(1)--style transfer

    一.opencv的示例模型文件   使用Torch模型[OpenCV对各种模型兼容并包,起到胶水作用], 下载地址: fast_neural_style_eccv16_starry_night.t7 ...

  6. 在调用self对象时,本类调用用Win32Info().collect()

    import platform class Test: def test(self): func = getattr(self,'windows') func() @staticmethod def ...

  7. Jmeter 时间函数工具汇总

    在使用Jmeter过程中,常使用的函数汇总 __time : 获取时间戳.格式化时间 ${__time(yyyy-MM-dd HH:mm:ss:SSS,time)}  :格式化生成时间格式 2018- ...

  8. QCamera检测摄像头

    The QCamera class provides interface for system camera devices. More... Header: #include <QCamera ...

  9. 阿里云服务器Svn-Server无法连接

    总结:关于阿里云服务器Svn-Server无法连接,Svn-Server的配置问题 2018年07月09日 11:51:08 周同学的博客 阅读数:355   最近在使用阿里云服务器时,SQL SER ...

  10. Dart中的类型转换总结:

    1.Dart中数组转换为字符串:join var a=[1,2,3,4]; var str=a.join(',');