首页 > 代码库 > 1143: 零起点学算法50——数组中查找数

1143: 零起点学算法50——数组中查找数

1143: 零起点学算法50——数组中查找数

Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld
Submitted: 1910  Accepted: 777
[Submit][Status][Web Board]

Description

在给定的数组中查找一个数

 

Input

多组测试,每组第一行输入1个整数n(n<20),然后是n个整数
第二行输入1个整数m

 

Output

查找在第一行的n个整数中第一次出现数字m的下标位置并输出,如果没有找到则输出No

 

Sample Input 技术分享

 
3 4 5 6
5
4 2 2 2 2
2

 

Sample Output

1
0

 

Source

零起点学算法

 
 1 #include<stdio.h>
 2 int main(){
 3     int n,a[20];
 4     while(scanf("%d",&n)!=EOF){
 5     for(int i=0;i<n;i++){
 6         scanf("%d",&a[i]);
 7     }
 8     int m,t,flag=1;
 9     scanf("%d",&m);
10     for(int i=0;i<n;i++){
11         if(m==a[i]){
12             t=i;
13             flag=0;
14             break;
15         }
16     }
17     if(flag)
18     printf("No\n");
19     else
20     printf("%d\n",t);
21     }
22     return 0;
23 }

 

1143: 零起点学算法50——数组中查找数