9 degrees OJ 1052 find x, 9 degrees oj1052

Source: Internet
Author: User

9 degrees OJ 1052 find x, 9 degrees oj1052

Question 1052: Find x

Time Limit: 1 second

Memory limit: 32 MB

Special question: No

Submit: 5182

Solution: 2761

Description:

Input n numbers, input n numbers are different, input another value x, output the subscript of this value in this array (starting from 0, if not in the array, output-1 ).

Input:

There are multiple groups of test data. Input n (1 <= n <= 200), then input n numbers, and then input x.

Output:

Output results for each group of inputs.

Sample input:
21 30
Sample output:
-1
#include<stdio.h>int data[201];int main(int argc, char *argv[]){    int n;    int i;    for(i=0;i<201;++i)        data[i]=-2;    while(scanf("%d",&n)!=EOF)    {        int tmp;        for(i=0;i<n;++i){            scanf("%d",&tmp);            data[tmp]=i;        }        scanf("%d",&tmp);        if(data[tmp]!=-2)            printf("%d\n",data[tmp]);        else            printf("-1\n");    }     return 0;} /**************************************************************    Problem: 1052    User: kirchhoff    Language: C    Result: Accepted    Time:0 ms    Memory:916 kb****************************************************************/



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.