当前位置:网站首页>-查找数-
-查找数-
2022-08-03 05:10:00 【-JMY-】
题目描述
已知一个长度为10且已经按照从小到大排序的整形数组,要求对于输入的每一个整数,判断该数在数组中的位置并且输出。如果数组中不存在这个数,输出error.
输入
输入10个数,顺序从小到大,输入一个n ,n代表随后要查找n次,随后输入n个要查找的数。
输出
输出查找的结果。
样例输入
1 2 3 4 5 6 7 8 9 10 5 1 4 7 8 11
样例输出
1 4 7 8 error
参考代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
bool flag;
int a[11],b[10005],n;
for(int i=1;i<=10;i++)
scanf("%d",a+i);
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",b+i);
for(int i=1;i<=n;i++){
flag=true;
for(int j=1;j<=10;j++){
if(b[i]==a[j]){
flag=false;
printf("%d\n",j);
break;
}
}
if(flag)
printf("error\n");
}
}
边栏推荐
猜你喜欢
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
第三次HarmonyOS培训
曲线特征----曲线弯曲程度的探究
Modelarts第一次培训
ModelArts第二次培训
js implements a bind function
在树莓派上搭建属于自己的网页(2)
Installation of Apache DolphinScheduler version 2.0.5 distributed cluster
PotPlayer实现上班摸鱼电视自由
UV decomposition of biotin - PEG2 - azide | CAS: 1192802-98-4 biotin connectors
随机推荐
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
Djiango第三次培训
Talking about GIS Data (6) - Projected Coordinate System
JDBC与连接池
[Fine talk] Using native js to implement todolist
Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures
高可用 两地三中心
MOSN 反向通道详解
初步认识ZK
shell script loop statement
JS学习笔记(三)
typescript40-class类的保护修饰符
传说中可“免费白拿”的无线路由器 - 斐讯 K2 最简单刷 breed 与第三方固件教程
ss-1.curl (cloud-provider-payment8001)
web安全-命令执行漏洞
[Harmony OS] [ArkUI] ets development graphics and animation drawing
Response 重写设置返回值
mysql 存储过程 动态参数 查询执行结果
1059 C语言竞赛 (20 分)(C语言)
【Flask】Flask-SQLAlchemy的增删改查(CRUD)操作