Uva11991easy problem from rujia Liu? (MAP + vector)

Source: Internet
Author: User

Question: uva11991easy problem from rujia Liu? (MAP + vector)


Give you n numbers, which may be repeated. Then, in m queries, ask the subscript of the k V. If such a number does not exist, output 0.


Solution: map each number and subscript for one-to-one ing, but because the same number appears multiple times, an array is required and the length is not certain, so vector is used.


Code:

# Include <cstdio> # include <map> # include <vector> using namespace STD; Map <int, vector <int> vis; // do not concatenate int main () {int n, m; int v, k; while (scanf ("% d", & N, & M )! = EOF) {vis. clear (); // clear for (INT I = 1; I <= N; I ++) {scanf ("% d", & V); If (! VIS. count (V) vis [v] = vector <int> (); // create an array vis [v]. push_back (I) ;}for (INT I = 0; I <m; I ++) {scanf ("% d", & K, & V ); if (! VIS. count (v) | Vis [v]. size () <k) printf ("0 \ n"); elseprintf ("% d \ n", vis [v] [k-1]);} return 0 ;}


Uva11991easy problem from rujia Liu? (MAP + vector)

Related Article

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.