UVA10474 Where is the Marble?

Source: Internet
Author: User

Question Link: UVA10474 Where is the Marble?.

Test Instructions Description: Enter n integers, representing the marble number, and then enter Q number (number), ask if there is this number of marble, where is the location?

This problem is written in the C + + language program, mainly to practice the use of STL functions.

The program uses two functions in the algorithm library (algorithm), uses the sort () function to sort the data, the function's parameters are simpler than the similar functions of the C language, the program is easier to write, and the function Lower_bound () to find the elements is simple and convenient.


The AC C + + language program is as follows:

/* UVA10474 Where is the Marble? */#include <iostream> #include <algorithm>using namespace std; #define MAXN 11000int Marble[maxn];int Main () {    int n, Q, Caseno=0, Val;    while (scanf ("%d%d", &n, &q)! = EOF) {        if (n = = 0 && q = = 0) break            ;        for (int i=0; i<n; i++)            scanf ("%d", &marble[i]);        Sort (marble, marble + N);        printf ("case#%d:\n", ++caseno);        while (q--) {            scanf ("%d", &val);            int no = Lower_bound (marble, Marble + N, Val)-Marble;            if (marble[no] = = val)                printf ("%d found at%d\n", Val, no + 1);            else                printf ("%d not found\n", Val);        }    }    return 0;}


UVA10474 Where is the Marble?

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.