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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM