删数问题软件测试项目,1144: 零起点学算法51——数组中删数(C语言)

题目:

源代码:

#include

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的话,原样输出

截图:

0afee6fd0ce9de205770ec32bff92f54.png

1145&colon; 零起点学算法52——数组中删数II

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

Problem D&colon; 零起点学算法83——数组中删数

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

Problem E&colon; 零起点学算法84——数组中删数II

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

Problem F&colon; 零起点学算法85——数组中插入一个数

#include int main() { ],b[]; while(scanf("%d",&n)!=EOF) { ;i

Problem C&colon; 零起点学算法82——数组中查找数

#include int main(void) { ],m; while(scanf("%d",&n)!=EOF) { ;i

1129&colon; 零起点学算法36——3n&plus;1问题

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

1164&colon; 零起点学算法71——C语言合法标识符(存在问题)

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

1163&colon; 零起点学算法70——Yes&comma;I can&excl;

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

1147&colon; 零起点学算法54——Fibonacc

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

随机推荐

使用C&plus;&plus;11的一点总结

C++11已不是新鲜技术,但对于我来说,工作中用得还不够多(前东家长时间使用gcc3.4.5,虽然去年升了4.8.2,但旧模块维护还是3.4.5居多:新东家用的是4.4.6,不能完整支持C ...

微信开发03----------XML解析与封装

3.1 解析微信发来的请求  微信服务器发来的请求消息都被封装在request对象中,可以从request对象中将请求参数取出来.通常是用request的getParament()方法获取请求中的参数 ...

ADO&period;NET连接数据库的两种方式

//实现了IDisposable接口的类,用using括起来 //插入数据 string connString = "Data Source=(local);Initial Catalog= ...

AFNetworking使用总结

AFNetworking使用总结   关于AFNetworking使用总结 以及一些错误的解决办法. AD:WOT2015 互联网运维与开发者大会 热销抢票 AFNetworking使用总结 分享类型 ...

tensorflow estimator API小栗子

TensorFlow的高级机器学习API(tf.estimator)可以轻松配置,训练和评估各种机器学习模型. 在本教程中,您将使用tf.estimator构建一个神经网络分类器,并在Iris数据集上 ...

visual studio 2015百度云下载

visual studio 2015百度云下载 https://pan.baidu.com/s/1b198Zo3mX5_zA2VX3xRRfw 提取码: 关注公众号[GitHubCN]回复2015获取

Linux 内核编译问题

linux0.12 编译过程 https://www.bbsmax.com/A/GBJrMb0Kz0/ http://www.cnblogs.com/strugglesometimes/p/42313 ...

tinyweb集成springmvc 的一种可行方式

最近tiny项目中集成了springmvc,而且使用的tiny的版本比较低,所以整合起来官网给的前两种方式都行不通. 而且有个tiny整合springmvc的maven依赖都下载不了.所以只有使用第三 ...

【324】Python 库说明&lpar;安装&amp&semi;卸载&rpar;

参考:Python_安装官方whl包和tar.gz包 参考:Unofficial Windows Binaries for Python Extension Packages 参考:PyPI 参考:直 ...

&lbrack;Cracking the Coding Interview&rsqb; 4&period;4 Check Balanced

Implement a function to check if a binary tree is balanced. For the purpose of this question, a bala ...

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值