Title Description
http://acm.nyist.net/JudgeOnline/problem.php?pid=285
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
-
Aaaaaa
Acacac
Gttttg
Acacac
Gttttg
Acacac
Acacac
Tccccc
Tccccc
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
- Input
- Number of sequences not exceeding 20000, no more than 20 characters per sequence
Input ends at 0 0
- Output
-
- As described in the title of the output can
- Sample input
-
-
9 6AAAAAAACACACGTTTTGACACACGTTTTGACACACACACACTCCCCCTCCCCC0 0
- Sample output
-
120100000
-
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)