Use Mapp for the second time. The data structure is a good thing.

Source: Internet
Author: User

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.

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.