1144: 零起点学算法51——数组中删数(C语言)
题目:
源代码:
#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
结果:
注意:
- 多组输入
- 最后换行
- 删除后没有数的话,不需要输出任何东西
- 数组中没有m的话,原样输出
截图:
1144: 零起点学算法51——数组中删数(C语言)的更多相关文章
- 1145: 零起点学算法52——数组中删数II
1145: 零起点学算法52--数组中删数II Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 293 ...
- Problem D: 零起点学算法83——数组中删数
#include<stdio.h> int main(void) { int n,i,t,x,flag; while(scanf("%d",&n)!=EOF) ...
- Problem E: 零起点学算法84——数组中删数II
#include<stdio.h> int main() { ],b[],i,flag=; while(scanf("%d",&n)!=EOF) { ;i< ...
- Problem F: 零起点学算法85——数组中插入一个数
#include<stdio.h> int main() { ],b[]; while(scanf("%d",&n)!=EOF) { ;i<n;i++) ...
- Problem C: 零起点学算法82——数组中查找数
#include<stdio.h> int main(void) { ],m; while(scanf("%d",&n)!=EOF) { ;i<n;i++ ...
- 1129: 零起点学算法36——3n+1问题
1129: 零起点学算法36--3n+1问题 Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 4541 ...
- 1164: 零起点学算法71——C语言合法标识符(存在问题)
1164: 零起点学算法71——C语言合法标识符 Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 10 ...
- 1163: 零起点学算法70——Yes,I can!
1163: 零起点学算法70--Yes,I can! Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: ...
- 1147: 零起点学算法54——Fibonacc
1147: 零起点学算法54--Fibonacc Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 20 ...
随机推荐
- ubuntu之路——day8.3 RMSprop
RMSprop: 全称为root mean square prop,提及这个算法就不得不提及上篇博文中的momentum算法 首先来看看momentum动量梯度下降法的过程: 在RMSprop中: C ...
- Android反编译,apk反编译技术总结
1.谷歌提供的工具:android-classyshark 下载地址:https://github.com/google/android-classyshark/releases,下载下来之后是一个可 ...
- SelectKBest
https://www.e-learn.cn/content/python/2198918from sklearn.feature_selection import SelectKBest,f_cla ...
- [java.lang.NoSuchMethodError: org.hibernate.Session.createQuery(Ljava/lang/String;)Lorg/hibernate/query/Query;]
jar包冲突 maven导入的jar包和自己将lib目录的jar同时加入了项目里面了
- html访问图片资源403问题(http referrer)
前言 之前碰到一个问题,就是html中通过img标签引入一个图片地址,报403.但是这个图片地址直接复制出来在地址栏打开,却是看得到的. 先说下解决方法: 在HTML代码的head中添加一句& ...
- Git: git tag 使用小结(给发布版本打标记,切换并修改某个历史版本)
通常在软件发布的时候会打一个tag,用于标注这次发布的相关信息, 这样做的好处是,将来如果这个版本出现了问题,可以通过tag迅速定位到当前版本,进行错误修复. 1. 新建tag $ git tag v ...
- MySQL 正则(Regular Expression) 邮箱(Email)
MySQL 正则表达式 | 菜鸟教程https://www.runoob.com/mysql/mysql-regexp.html (1条消息)常用正则表达式—邮箱(Email) - Samuel - ...
- Jenkins自动化版本构建
1.拉取代码 2.更新父版本 更新依赖版本 3.打包并推送到maven私库 4.版本控制后提交代码并打成docker镜像 PS:修改pom.xml项目版本,这里我没使用插件,直接使用脚本进行修改,这样 ...
- 一、jenkins下载及安装
一.安装 官网地址:https://jenkins.io/zh/ 1.下载war包,放到tomcat——>webapps下,双击bin——>startup.bat启动 2.打开命令提示符. ...
- linux系统执行.exe文件
首先要了解一下Wine: Wine (“Wine Is Not an Emulator” 的首字母缩写)是一个能够在多种 POSIX-compliant 操作系统(诸如 Linux,Mac OSX 及 ...