The D country where bears live is a country full of respect for human rights. It is so strange that all the people in this country name their names. A person's name is made up of several characters, and the same is true of each string in the result of the full arrangement of these characters. For example, if a person's name is ACM, then AMC, CAM, MAC, MCA, etc. are also the names of this person. In this country, there are not two people with the same name.
Degree bears want to count the number of people in this country, help a bear to design a program that counts how many times each person has been counted before.
Input
This includes a set of test data, the first line containing a positive integerNnN, the nextNnn line represents nnn a name. nn n will not exceed 100,000100,000 100 ,000, their name will not exceed 40 bits.
Output
For each name entered, output an integer representing how many times the person was counted.
Sample InputCopy
5ACMMACBBAACMBAB
Sample OutputCopy
01021
This topic is characterized by the use of a sort and then map (PS data structure is a good thing)
For this string lookup problem MAPP structure is a good thing ah.
Put code on it.
#include <cstdio>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
using namespace Std;
BOOL CMP (char X,char y)
{
Return x-y>0;
}
int main ()
{
int t,mem[41];
string S;
Char rem[41];
Map<string,int> fuck;
while (~SCANF ("%d", &t))
{
int i,j;
for (i=1;i<=t;i++)
{
int sum=0;
cin>>s;
Sort (S.begin (), S.end (), CMP);//The sorting of string types is well-written. S.begin () S.end ()
if (i==0)
{
printf ("0\n");
Continue
}
if (Fuck.find (s)!=fuck.end ()) fuck[s]++;
else fuck[s]=0;
printf ("%d\n", Fuck[s]);
}
}
return 0;
}
Use Mapp for the second time. The data structure is a good thing.