zoukankan      html  css  js  c++  java
  • 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
    ");
    19     else
    20     printf("%d
    ",t);
    21     }
    22     return 0;
    23 }
  • 相关阅读:
    pm2
    php 基础知识
    EBADF, read
    php apache
    noah
    ejs
    node linux
    枚举系统进程
    c++ 进程权限的提升
    Liunx的目录结构
  • 原文地址:https://www.cnblogs.com/dddddd/p/6680679.html
Copyright © 2011-2022 走看看