Nyoj 285 looking for clones (map+ count)

Source: Internet
Author: User

Title Description


A small town in the United States was recently attacked by aliens and some residents were taken away and cloned, and now scientists have extracted DNA from some people in the town, identifying the number of DNA with the same number of clones, such as the following 9 sequences

Where TCCCCC,GTTTTG have two identical individuals, ACACAC have four, aaaaaa is one, then the number of rows corresponding to the output

First row 1, second row 2, fourth row 1, other row output 0, total 9 rows

Number of sequences not exceeding 20000, no more than 20 characters per sequence
Input ends at 0 0

As described in the title of the output can
Sample input

Sample output

Topic Analysis:

The problem is that the number of strings that appear I, and the output, is a map+ count. Use an array of a[] to record the number of occurrences, such as a[i]=4; The string representing the occurrence of I is 4.

AC Code:

/** * Hash + count */#include <iostream> #include <cstdio> #include <map> #include <cstring> #include <string> #include <algorithm> #include <queue> #include <vector> #include <stack># include<cstdlib> #include <cctype> #include <cstring> #include <cmath>using namespace Std;int a [20005];int Main () {    int n,m;    while (cin>>n>>m&&n+m) {        string str;        Map<string, int> hp;        memset (A,0,sizeof (a));        for (int i=0;i<n;i++) {            cin>>str;            hp[str]++;        }        Map<string, int>::iterator it;        For (It=hp.begin (); It!=hp.end (); ++it) {            ++a[it->second];//count        } for        (int i=1;i<=n;i++) {            cout<<a[i]<<endl;        }    } return 0;}        

Nyoj 285 looking for clones (map+ count)

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.