NYOJ 285 search for clone (map + count)
Description
A town in the United States was recently attacked by aliens. Some residents were taken away and cloned. Now, scientists have extracted the DNA of some people in the town. Please find out the number of DNA with the same number of clones, for example, the following nine Sequences
AAAAAA
ACACAC
GTTTTG
ACACAC
GTTTTG
ACACAC
ACACAC
TCCCCC
TCCCCC
Here, TCCCCC and GTTTTG have two identical individuals, four for ACACAC and one for AAAAAA respectively, then the number of corresponding lines is output.
The first row 1, the second row 2, and the fourth row 1. The other rows output 0, 9 rows in total.
-
The number of input sequences cannot exceed 20000, and each sequence cannot exceed 20 characters
Input ends with 0
-
For example, describe the output in the question.
9 6AAAAAAACACACGTTTTGACACACGTTTTGACACACACACACTCCCCCTCCCCC0 0
-
Sample output
120100000
Question Analysis:
The question is that finding and outputting the number of strings that appear I times is a map + counting problem. Use an array a [] to record the number of occurrences, for example, a [I] = 4; to indicate that the number of occurrences of I is 4.
AC code:
/*** Hash + count */# include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; int a [20005]; int main () {int n, m; while (cin> n> m & n + m) {string str; map
Hp; memset (a, 0, sizeof (a); for (int I = 0; I
> Str; hp [str] ++;} map
: Iterator it; for (it = hp. begin (); it! = Hp. end (); ++ it) {++ a [it-> second]; // count} for (int I = 1; I <= n; I ++) {cout <
-
-